Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot inside a loop in MATLAB

Tags:

plot

matlab

I am doing something like this:

a = [1:100];
for i=1:100,
    plot([1:i], a(1:i));
end

My issue is that the plot is not shown until the loop is finished. How can I show/update the plot in every iteration?

like image 821
Macarse Avatar asked May 10 '10 02:05

Macarse


People also ask

How do you plot data changes in Matlab?

Update Plot Using Data LinkingCreate the variable x to represent the iteration number and y to represent the approximation. Plot the initial values of x and y . Turn on data linking using linkdata on so that the plot updates when the variables change. Then, update x and y in a for loop.


1 Answers

Use DRAWNOW

a = [1:100];
for i=1:100,
 plot([1:i], a(1:i));
 drawnow
end

Alternatively, you may want to have a look at ANYMATE from the file exchange.

like image 95
Jonas Avatar answered Oct 11 '22 09:10

Jonas