Matlab updating subplots and hold on

拟墨画扇 提交于 2019-12-06 00:20:44

I am a bit puzzled why your example does not work as expected, but changing hold on; to hold(win.sub2, 'on'); seems to produce the desired result.

Note: when executing your example code, matlab gives me a warning, probably because the second line overwrites win as defined in the first line.

The problem seems to be that hold on does not affect the right axis. You can solve it using set(...,'Nextplot','add') on the intended axis. To do it sumultaneaously on all axes, it's much easier if win is an array instead of a struct. And by the way, line 1 is useless (win is overwritten).

So, the code would be:

win(1) = subplot(2, 2, 1);
win(2) = subplot(2, 2, 2);
win(3) = subplot(2, 2, 3);
win(4) = subplot(2, 2, 4);

set(win,'Nextplot','add') %// set this for all axes in variable win

x = 1:1:10;

plot(win(2), x, x); %graphs the line y = x in the second subplot, good.
plot(win(2), x, -x) %ought to plot line y = -x over line y = x, but does not.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!