在 MATLAB 中循环内部绘图
我正在做这样的事情:
a = [1:100];
for i=1:100,
plot([1:i], a(1:i));
end
我的问题是在循环完成之前不会显示绘图。 如何在每次迭代中显示/更新绘图?
I am doing something like this:
a = [1:100];
for i=1:100,
plot([1:i], a(1:i));
end
My issue is that the plot is not shown until the loop is finished.
How can I show/update the plot in every iteration?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 DRAWNOW
或者,您可能想看看来自文件交换的 ANYMATE。
Use DRAWNOW
Alternatively, you may want to have a look at ANYMATE from the file exchange.
如果您只想将其可视化而不保存动画,则另一种方法是使用
refreshdata
而不是plot
进行后续绘图。您仍然需要调用drawnow
才能使其在屏幕上更新。无论是使用
还是用于
您的示例,这可能看起来像:
对于简单的线图来说并不是那么有用(对于其中
plot();drawow;
更简单更快),但是当您需要创建涉及多种绘图类型的更复杂的图形,这可能很有用。Another way to do this if you just want to visualise it without saving the animation, is to use
refreshdata
instead ofplot
for subsequent plots. You will still need to calldrawnow
for it to update on-screen.either use
or use
for your example, this might look like:
It's not all that useful for simple line plots (for which
plot(); drawnow;
is simpler and faster), but when you need to create more complicated figures involving multiple plot types, this can be useful.来自 comet.m 文档
From the documentation for comet.m
Matlab 允许您对变量的循环语句进行排序自动化
就是一个例子……
很多时候您并不需要在循环中进行绘制
Matlab
allows you to sort-of automate a loop statement for variablesis an example......
A lot of times you don't really need to plot 'in' a loop