Continuous plot in MATLAB

后端 未结 3 1178
后悔当初
后悔当初 2020-12-20 02:19

I have a loop in my code and I want to plot some variables,

In each iteration I plot a new point and I want it to be connected to the previous point.

Here is

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-20 02:38

    I would replace your existing plot line with this one

    plot(t(1:i),s(1:i)); hold on;
    

    That will plot all of the points from index 1 until the current index. Then, by removing the 'bo', it'll plot using the default format, which is the line that you desire.

    Finally, if you want this to actually be animated on the screen (like a movie), you'll need to add a drawnow command before the end of your loop. You also might want to add a pause(0.25) after the draw, to insert a quarter-second delay so that your eye has a chance to see the newly drawn image before it gets overwritten by the next drawing of the image.

提交回复
热议问题