问题描述
我打开了多个图形,我想在运行时独立更新它们.以下玩具示例应阐明我的意图:
I have multiple figures open, and I want to update them independently during runtime. The following toy example should clarify my intention:
clf;
figure('name', 'a and b'); % a and b should be plotted to this window
hold on;
ylim([-100, 100]);
figure('name', 'c'); % only c should be plotted to this window
a = 0;
b = [];
for i = 1:100
a = a + 1;
b = [b, -i];
c = b;
xlim([0, i]);
plot(i, a, 'o');
plot(i, b(i), '.r');
drawnow;
end
这里的问题是,当我打开第二个figure
时,我无法告诉plot
函数将其绘制到第一个,而不是第二个(并且仅c
应该绘制到第二个). /p>
The problem here is that when I open the second figure
, I cannot tell the plot
functions to plot to the first one instead of the second (and only c
should be plotted to the second).
推荐答案
您可以使用
figure(1)
plot(x,y) % this will go on figure 1
figure(2)
plot(z,w) % this will go on another figure
该命令还将使图形可见并位于所有内容的顶部.
The command will also set the figure visible and on top of everything.
您可以根据需要通过发出相同的figure
命令在图之间来回切换.另外,您也可以使用图形的手柄:
You can switch back and forth between the figures as necessary by issuing the same figure
command. Alternatively, you can use the handle to the figure as well:
h=figure(...)
,然后发出figure(h)
而不是使用数字索引.使用此语法,您还可以通过使用
and then issue figure(h)
instead of using numeric indices. With this syntax, you can also prevent the figure from popping up on top by using
set(0,'CurrentFigure',h)
这篇关于我如何指定绘图应移至哪个图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!