필터 지우기
필터 지우기

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 CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by