LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 11-29-2005, 10:25 AM   #1
mshinska
LQ Newbie
 
Registered: Oct 2005
Posts: 14

Rep: Reputation: 0
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.
 
Old 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,004

Rep: Reputation: 624Reputation: 624Reputation: 624Reputation: 624Reputation: 624Reputation: 624
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.
 
Old 11-29-2005, 08:25 PM   #3
butters64
LQ Newbie
 
Registered: Nov 2005
Distribution: Mandrake LE2003 64
Posts: 13

Rep: Reputation: 0
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.
 
Old 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,004

Rep: Reputation: 624Reputation: 624Reputation: 624Reputation: 624Reputation: 624Reputation: 624
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.
 
Old 12-07-2005, 08:22 AM   #5
mshinska
LQ Newbie
 
Registered: Oct 2005
Posts: 14

Original Poster
Rep: Reputation: 0
thanks

thanks for the help everyone i got ut to work.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
graphing calculator Four Programming 3 11-28-2005 05:28 PM
Graphing TuxFreak Linux - Software 1 02-27-2005 04:29 PM
Terminal cmd for starting Matlab M-file editor without starting matlab fubzot Linux - Software 2 02-15-2005 06:49 AM
graphing a new hard to slackware djgerbavore Slackware 1 08-05-2004 03:23 PM
Graphing AMMullan Linux - Software 1 11-16-2003 01:11 AM


All times are GMT -5. The time now is 09:39 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration