Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Help plotting with pauses after each point

Subject: Help plotting with pauses after each point

From: Kaye

Date: 10 Dec, 2012 16:33:09

Message: 1 of 5

Hi,
I am currently try to make a code which runs a random walk. I am plotting the random walk on a graph, but I want to make it so it plots one point at a time. ( i am making this so at each stage the user can guess whether it will go up or down the next step)Is there a way I can make it plot one point, then have an input box that say "up or down?" then the user enters 'up' or 'down' and it shows the next point on the graph?
This is my code so far to do the random walk:
rand('state',123);
s = rand(1,100); %100 steps
d = cumsum(((s > 0.5)*2) - 1);%d is the cumulative distance from the origin
plot(d)

Thanks
 

Subject: Help plotting with pauses after each point

From: someone

Date: 10 Dec, 2012 19:47:18

Message: 2 of 5

"Kaye" wrote in message <ka52s5$fkl$1@newscl01ah.mathworks.com>...
> Hi,
> I am currently try to make a code which runs a random walk. I am plotting the random walk on a graph, but I want to make it so it plots one point at a time. ( i am making this so at each stage the user can guess whether it will go up or down the next step)Is there a way I can make it plot one point, then have an input box that say "up or down?" then the user enters 'up' or 'down' and it shows the next point on the graph?
> This is my code so far to do the random walk:
> rand('state',123);
> s = rand(1,100); %100 steps
> d = cumsum(((s > 0.5)*2) - 1);%d is the cumulative distance from the origin
> plot(d)
>
> Thanks
>

I don't have MATLAB installed on this computer,
but you should be able to do something like:

rand('state',123);
s = rand(1,100); %100 steps
d = cumsum(((s > 0.5)*2) - 1);%d is the cumulative distance from the origin
for ii = 1:size(s)
   clear all
   plot(d(1:ii))
   answer = inputdlg('up or down?')
end

The above is very inelegant, but should get you started.
I'll leave the details to you, (i.e., what to do with answer).

doc inputdlg

(or one of the other "See Also" at the end of the help.

Subject: Help plotting with pauses after each point

From: Kaye

Date: 11 Dec, 2012 12:00:08

Message: 3 of 5

Thanks, I have managed to get it to pause after each point. Is there a way i can make the input box appear after every pause?
Can i put it in a loop somehow maybe?

Subject: Help plotting with pauses after each point

From: someone

Date: 11 Dec, 2012 14:56:07

Message: 4 of 5

"Kaye" wrote in message <ka7788$bp9$1@newscl01ah.mathworks.com>...
> Thanks, I have managed to get it to pause after each point. Is there a way i can make the input box appear after every pause?
> Can i put it in a loop somehow maybe?
In the above code the input box is already inside a for loop.
If it is not appearing after every pause, perhaps inserting
a DRAWNOW command after the inputdlg will solve the problem.

Also you may want to consider using a while loop instead of a for loop in the above code and depending on the value of answer, allow yourself to break out of the loop.
(Unless you really want to "pause" each plot 100 times or so.)

Subject: Help plotting with pauses after each point

From: Viswanath D

Date: 10 Nov, 2014 05:05:10

Message: 5 of 5

"Kaye" wrote in message <ka7788$bp9$1@newscl01ah.mathworks.com>...
> Thanks, I have managed to get it to pause after each point. Is there a way i can make the input box appear after every pause?

Hello,Kaye..can you please share the code for plotting with pauses.thanks

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us