在 MATLAB 中的循环内绘图时的连续绘图 [英] Continuous plot while plotting inside a loop in MATLAB

查看:116
本文介绍了在 MATLAB 中的循环内绘图时的连续绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 MATLAB 中动态绘制变量.我有一个需要随时间绘制的数组(状态集).我试过 plot(time,theta),其中 theta 是一个 1*5 的数组.使用此命令,我收到一条错误消息,指出 theta 应该是标量,因为时间是标量.然后我尝试使用 for 循环来绘制(时间,θ(i)).这样做的问题是我在我的绘图上以离散的时间间隔获得数据点.但是我需要一个连续的情节.我想知道如何做到这一点.

I am trying to plot variables dynamically in MATLAB. I have an array (set of states) that needs to be plotted with time. I tried plot(time,theta), where theta is a 1*5 array. With this command, I get an error saying that theta should be a scalar because time is a scalar. I then tried using for-loop to plot(time,theta(i)). The problem with this is that I get data points at discrete time intervals on my plot. However I need a continuous plot. I wonder how this can be done.

推荐答案

绘图时需要使用hold on.

例如:

time = 1;
theta = [1:100];
figure

for i=1:100

    plot(time, theta(i),'r.')
    hold on  %--> Keeps the previous data in your plot
    time = time + 1;

end

这篇关于在 MATLAB 中的循环内绘图时的连续绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆