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, 11: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, 12:51 PM #2 schneidz LQ Guru   Registered: May 2005 Location: boston, usa Distribution: fc-15/ fc-20-live-usb/ aix Posts: 5,150 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 01:33 PM.
 11-29-2005, 09: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, 11:02 PM #4 schneidz LQ Guru   Registered: May 2005 Location: boston, usa Distribution: fc-15/ fc-20-live-usb/ aix Posts: 5,150 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 11:08 PM.
 12-07-2005, 09: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.

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Four Programming 3 11-28-2005 06:28 PM TuxFreak Linux - Software 1 02-27-2005 05:29 PM fubzot Linux - Software 2 02-15-2005 07:49 AM djgerbavore Slackware 1 08-05-2004 04:23 PM AMMullan Linux - Software 1 11-16-2003 02:11 AM

LinuxQuestions.org

All times are GMT -5. The time now is 09:07 PM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -