help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: plot in a for loop


From: William Krekeler
Subject: RE: plot in a for loop
Date: Wed, 2 Mar 2011 21:27:30 +0000

Alternative solution for plotting in a loop, replace the lines inside the for 
loop with the following where newdata is the information you wish to plot

hold on, plot( newdata ), hold off; drawnow; pause(0.1)

This code will allow the previous plots to persist so you can see the 
iterations. Alternatively remove the hold commands to update the plots.

Bill Krekeler

-----Original Message-----
From: address@hidden [mailto:address@hidden On Behalf Of Richardson, Anthony
Sent: Wednesday, March 02, 2011 10:24 AM
To: Mon; address@hidden
Subject: RE: plot in a for loop

> Morning all,
> I know this has been addressed in the past, but I cannot find the
> relavent
> post in the archive.
> 
> I am tring to plot some data in a for loop, but once the first
> iteration
> prints, the plot window has the focus and none of the other iterations
> print.
> 
> figure
> #hold on
> for i=1:size(x,1)
> plot(x{i},y{i})
> #drawnow
> endfor
> 
> "drawnow" doesn't get it, nor does "hold on"

I assume you are getting updates to the vector inside the
loop and also want to update the plot.

The script below should point you in the right direction.
It appends new data to the underlying handle graphics object
each time through the loop.  (This may actually be completely
erasing and redrawing the play each time through the loop 
(I'm not sure), but it gives the illusion of a real-time data
plot.)

===============================
N = 200;
figure (1)
x = 0:(N-1);
y = rand(1, length(x));
plot(x(1), y(1));
axis([0 N 0 1]);
vh = get(gca,'children');
for i=1:length(x)
        set(vh, 'xdata',x(1:i), 'ydata', y(1:i));
        pause(0.1);
endfor
================================================

Tony Richardson

_______________________________________________
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave


reply via email to

[Prev in Thread] Current Thread [Next in Thread]