How to make only the second plot changing in a loop?

2 visualizaciones (últimos 30 días)
5mid
5mid el 12 de Oct. de 2016
Comentada: 5mid el 13 de Oct. de 2016
I'm doing something like this:
imagesc(pher_mat)
hold on
for i=1:5000
figure(1)
plot(x,y)
end
But this is adding more and more plots to the figure and I only want the first imagesc(pher_mat) and the last of each loop to be plotted. And I don't want imagesc(pher_mat) inside the loop of course.
Thanks

Respuesta aceptada

dpb
dpb el 12 de Oct. de 2016
imagesc(pher_mat)
hold on
% figure(1) % figure won't change unless somewhere else there's another referenced
for i=1:5000
... % whatever changes x,y here during the loop
end
plot(x,y) % plot the last when the loop's done...
Leaves you with the visual as described -- now it the loop is very time-consuming, nothing shows until it's done, but if you don't want the intermediates to show, then don't plot 'em...
OTOH, you could "have your plot and eat it too", if you simply updated the [X|Y]Data property each pass--
imagesc(pher_mat)
hold on
i=1;
% do whatever needed for the first case to get x,y
hL=plot(x,y) % create the first plot, save line handle
for i=2:5000 % now the rest in loop
... % whatever changes x,y here during the loop
set(hL,'XData',x,'YData',y) % and update each pass
end
You can also do things like compute mod(i,10), say, and do every 10th or whatever...
"Salt to suit!" :)
  1 comentario
5mid
5mid el 13 de Oct. de 2016
The second one was the one I wanted and works well!! Thank you

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by