我做這樣的事情:情節MATLAB
a = [1:100];
for i=1:100,
plot([1:i], a(1:i));
end
我的問題是不顯示的情節,直到循環結束。 如何在每次迭代中顯示/更新繪圖?
我做這樣的事情:情節MATLAB
a = [1:100];
for i=1:100,
plot([1:i], a(1:i));
end
我的問題是不顯示的情節,直到循環結束。 如何在每次迭代中顯示/更新繪圖?
如果您只想在不保存動畫的情況下對其進行可視化,另一種方法是使用refreshdata
而不是plot
作爲後續繪圖。您仍需要撥打drawnow
才能在屏幕上進行更新。
要麼使用
set(fig_handle,'XData',new_xdata_array)
set(fig_handle,'YData',new_ydata_array)
refreshdata
drawnow
或使用
set(fig_handle,'XDataSource',xdata_array)
set(fig_handle,'YDataSource',ydata_array)
%call this whenever xdata_array and ydata_array are assigned new values to see it updated in the plot
refreshdata
drawnow
爲你的榜樣,這可能是這樣的:
a=[1:100];
figure;
h=plot(1,a(1));
for i=2:100
set(h,'XData',[1:i])
set(h,'YData',a(1:i))
refreshdata
drawnow
end
這不是所有簡單的線圖是有用的(對於這plot(); drawnow;
更簡單和更快),但是當你需要創建更復雜的數字涉及多ple plot類型,這可能很有用。
t = 0:.01:2*pi;
x = cos(2*t).*(cos(t).^2);
y = sin(2*t).*(sin(t).^2);
comet(x,y);
當的DrawNow是正確的答案,我認爲一個人還可以在代碼中的DrawNow的位置添加一個暫停(EPS)語句。當matlab進行暫停時,即使只是對於時間片的這個納秒級分,它也會對圖形進行刷新。 – 2010-05-10 10:27:19