2014-06-16 35 views
2

我在更新子图时遇到问题。我煮了我的问题,下面的这个例子:Matlab更新子图并保留

win = figure(1); 
win.sub1 = subplot(2, 2, 1); 
win.sub2 = subplot(2, 2, 2); 
win.sub3 = subplot(2, 2, 3); 
win.sub4 = subplot(2, 2, 4); 

x = 1:1:10; 

plot(win.sub2, x, x); %graphs the line y = x in the second subplot, good. 
hold on; 
plot(win.sub2, x, -x) %ought to plot line y = -x over line y = x, but does not. 

当执行第二曲线,第一曲线,尽管上保持消失。似乎使这项工作的唯一事情是如果我使用坐标轴(win.sub2),但我试图避免这种情况,因为它确实会减慢我的程序(绘制一个图上的4个子图,每个子图都有大约2个重叠的图,创建一个1000 +帧电影)。我很感激任何帮助。谢谢

回答

1

我有点困惑为什么你的例子不能按预期工作,但将hold on;更改为hold(win.sub2, 'on');似乎产生所需的结果。

注意:在执行您的示例代码时,matlab会给我一个警告,可能是因为第二行覆盖了第一行中定义的win

+0

非常感谢你,我不知道,保持并没有简单地应用于所有轴... –

1

问题似乎是hold on不会影响右轴。您可以在预期轴上使用set(...,'Nextplot','add')来解决此问题。要在所有轴上同时执行,如果win是一个数组而不是一个结构,那么要容易得多。顺便说一下,第1行是无用的(win被覆盖)。

所以,代码如下:

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. 
+0

我很欣赏你的答案,并感谢解释保持并未影响右轴。这种洞察力是非常有价值的 –

+0

@KevinChan不客气! –

相关问题