How to make only the second plot changing in a loop?
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
dpb
2016-10-12
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!" :)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!