LinuxAnswers - the LQ Linux tutorial section.
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org matlab graphing
 Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game.

Notices

 11-29-2005, 10:25 AM #1 mshinska LQ Newbie   Registered: Oct 2005 Posts: 14 Rep: matlab graphing I am writing a code to plot a graph of everystep i've taken throughout the code. Right now it is only plotting one or two points. clc echo off clear all atHome = 0; stepsToTry = 5000; x = 0; y = 0; dx = 0; dy = 0; disp('Will Waldo make it home?') disp(' ') disp(' ') i = 0; while ( i <= stepsToTry & atHome == 0) angle = 2*pi*rand(); dx = cos(angle); dy = sin(angle); while (x + dx < -10 | x + dx > 10 | y + dy < -10 | y + dy > 10) angle = 2*pi*rand(); dx = cos(angle); dy = sin(angle); end x = x+dx; y = y+dy; if ( (x>=8) & (x<=10) & (y>=8) & (y<=10) ) atHome = 1; end i = i + 1; end if (atHome==1) disp('Waldo made it home in this many steps') disp(i) disp(' ') disp(' ') else disp('Waldo is still lost after taking this many steps') disp(stepsToTry) disp(' ') disp(' ') disp('Please play again and try to get Waldo home!') disp(' ') disp(' ') end hold on plot(x,y,'b') xlabel('x-axis') ylabel('y-axis') title('\fontsize{20}Waldo''s Path Home') hold off Thanks in advance for any help that you can give.
 11-29-2005, 11:51 AM #2 schneidz Senior Member   Registered: May 2005 Location: boston, usa Distribution: fc-15/ fc-20-live-usb/ aix Posts: 4,389 Rep: if i understand your question you want to graph multiple plots in your m-file. try: Code: `subplot(m,n,p)` _____________________ else if it is doing 1 or 2 traverses thru the while then 'atHome' is being arbitrarily set to 1. hth Last edited by schneidz; 11-29-2005 at 12:33 PM.
 11-29-2005, 08:25 PM #3 butters64 LQ Newbie   Registered: Nov 2005 Distribution: Mandrake LE2003 64 Posts: 13 Rep: Your plotting code: Code: ```hold on plot(x,y,'b') xlabel('x-axis') ylabel('y-axis') title('\fontsize{20}Waldo''s Path Home') hold off``` It looks like x and y are scalar variables, so this will only plot one point. I assume you want to plot a trail of these points? Have you tried removing "hold off"? Each plot command after "hold off" will automatically clear the plot. Hope this helps.
 12-06-2005, 10:02 PM #4 schneidz Senior Member   Registered: May 2005 Location: boston, usa Distribution: fc-15/ fc-20-live-usb/ aix Posts: 4,389 Rep: x isnt accumulating so either make it a vector or move the code butters posted inside the while. also using code tags will make your code easier to read. try putting 'why' before your end the while Last edited by schneidz; 12-06-2005 at 10:08 PM.
 12-07-2005, 08:22 AM #5 mshinska LQ Newbie   Registered: Oct 2005 Posts: 14 Original Poster Rep: thanks thanks for the help everyone i got ut to work.