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: Richardson, Anthony
Subject: RE: plot in a for loop
Date: Wed, 2 Mar 2011 10:24:16 -0600

> 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



reply via email to

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