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

3 ビュー (過去 30 日間)
5mid
5mid 2016 年 10 月 12 日
コメント済み: 5mid 2016 年 10 月 13 日
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

採用された回答

dpb
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!" :)
  1 件のコメント
5mid
5mid 2016 年 10 月 13 日
The second one was the one I wanted and works well!! Thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by