I am trying to do a dynamic plotting inside a nested loop in Matlab.This is somewhat similar to plot inside a loop.But I have one more loop. This is what my code looks like.
for i = 1:100
for j = 1:100
data(i,j) = fun(i,j);
end
end
plot(mean(data));
So I am plotting the mean data as an array. But for large iterations the plot shows only after the loop ends. Is there any way I can plot the data dynamically so something is plotted while the iteration goes on? How should I write the plot function inside the loops so I can achieve it?
P.S. : Actually there is some other functions running inside the loop the final value that is assigned to data(i,j) comes after some some complex calculations.The jth value that is assigned to data(i,j) is dependent on (j-1)th value and the very first value in the ith loop is some initial value. Also the mean(data) gets plotted which means I have to take the mean of the column data of the matrix which is returned as an array by the function mean(data).
plotinstruction is outside the loop in your example, so the plot will always be generated after the loop ends. (2) Is that all what your double loop does ? If yes you do not need a double loop but a single statement:data = bsxfun( @times , 1:100 , (1:100).' )bsxfunwill take longer execution time.XData/YDatawithin the loop.