在 Matlab 中绘图“while”环形
为什么我不能在同一窗口中绘制每次迭代的数据?我尝试使用drawnow
,但它不起作用。代码:
t=0;
T=10;
i =1;
while t<T
. . .
time(i)=(i-1)*delta_t;
scrsz = get(0,'ScreenSize');
figure('position',[80 60 scrsz(3)-110 scrsz(4)-150]);
subplot(1,3,1);
plot(time(i),configurations(1,1,i),'-b','LineWidth',2), hold on;
drawnow;
xlabel('Time[s]');
ylabel('X [m]');
subplot(1,3,2);
plot(time(i),configurations(3,1,i),'-b','LineWidth',2), hold on;
drawnow;
xlabel('Time[s]');
ylabel('Z [m]');
subplot(1,3,3);
plot(time(i),configurations(2,2,i),'-b','LineWidth',2), hold on;
drawnow;
xlabel('Time[s]');
ylabel('\phi [deg]');
t=t+1;
i=i+1;
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为您已在
while
循环内部添加了figure('...')
行。因此它每次迭代都会打开一个新窗口。移动该行和scrsz=...
行,并将其放置在while t 行上方(即,外部循环) 。
要绘制到多个图形窗口,请像这样使用轴句柄:
但是,每个
子图
都会创建自己的一个轴。因此,如果您想在循环内的两个不同窗口中绘制多个子图,则必须在循环之前设置它们,然后相应地调用。 IE,It's because you've added the
figure('...')
line inside thewhile
loop. So it opens a new window every iteration. Move that line and thescrsz=...
line and place it just above thewhile t<T
line (i.e., outside the loop).To plot to more than one figure window, use axes handles like so:
However, each
subplot
creates an axis of its own. So if you want to plot to multiple subplots in two different windows inside the loop, you'll have to set them up before the loop and then call accodringly. i.e.,