Real time plot in MATLAB

前端 未结 2 1294
天涯浪人
天涯浪人 2020-12-01 04:50

I\'m very new to MATLAB and I was trying to display a real time plot of some calculations. I have an N sized vector and I work with m values at a t

相关标签:
2条回答
  • 2020-12-01 05:23

    As Edric mentioned, you'll definitely want to include a drawnow command after the call to plot to force an update of the graphics. However, there is a much more efficient and smoother method to animate plots that doesn't involve recreating the entire plot each time. You can simply initialize your plot, capture a handle to the plot object, then modify the properties of that object in your loop using the set command. Here's an example:

    hLine = plot(nan);         % Initialize a plot line (which isn't displayed yet
                               %   because the values are NaN)
    for i = 1:N                % Loop N times
      ...
      % Compute m here
      ...
      set(hLine, 'YData', m);  % Update the y data of the line
      drawnow                  % Force the graphics to update immediately
    end
    

    In addition, before your loop and after the call to plot you can set a number of axes properties, like the axes limits, etc., if you want the axes to stay fixed and not change their appearance with each new vector m that is plotted.

    0 讨论(0)
  • 2020-12-01 05:35

    You can add a call to DRAWNOW to force the plot to update. See the reference page. Note that DRAWNOW causes the graphics event queue to be flushed, which may cause callbacks etc. to be executed.

    0 讨论(0)
提交回复
热议问题