Using hold and plotyy in a loop
2 ビュー (過去 30 日間)
古いコメントを表示
I am having trouble getting matlab to update plotyy in a loop.
I want extend a line of data as my code advance in time.
This is easily done for a single plot, as shown below for a simplified extract of my code
for year=1:1:year_max
%***Do Calcs
CalcStuff(year)
%***plot
figure(1)
subplot(3,1,[2 3]); cla; hold on;
%some stuff
subplot(311); hold on;
plot(year/1000,sum(State.Ice),'k.');
xlabel('Time (kyrs BP)')
ylabel ('Total Ice Mass')
drawnow;
end;
However, the similar code below for two lines using plotyy() is broken. The first Data point appears and STAYS on the plot (great), but all subsequent data are overwritten each loop (BAD!!).
for year=1:1:year_max
%***Do Calcs
CalcStuff(year)
%***plot
figure(1)
subplot(3,1,[2 3]); cla; hold on;
%some stuff
subplot(311); hold on;
[ax,h1,h2]=plotyy(year/1000,sum(State.Ice),year/1000,CO2ppmv);
set(h1, 'linestyle', '.','color','k'); set(ax(1), 'ycolor', 'k')
set(h2, 'linestyle', '.','color','r'); set(ax(2), 'ycolor', 'r')
hold(ax(1));hold(ax(2));
xlabel('Time (kyrs BP)')
ylabel ('Total Ice Mass')
drawnow;
end;
Any thoughts on how to fix this would be gratefully received!!
0 件のコメント
回答 (1 件)
Walter Roberson
2015 年 8 月 13 日
hold(ax(1), 'on'); hold(ax(2), 'on');
When you do not specify 'on' or 'off' the default is to toggle between on and off
参考
カテゴリ
Help Center および File Exchange で Two y-axis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!