首页 > 解决方案 > 有没有办法在matlab上绘制闭环系统的动画?

问题描述

matlab上是否有任何选项可以制作闭环系统的动画而不是图片?

我尝试使用 for 循环来改变阶跃响应的模拟时间,对于每个 for 循环交互,我尝试使用 step () 函数在一秒钟内模拟一个,但模拟函数仅显示第一次交互的结果,绘图结果图像必须随着时间的推移绘制多张图像以给人以动画的印象。

我希望看到系统的阶跃响应或斜坡响应随时间的演变。

我试图制作闭环传递函数动画的代码

在 Matlab 中使用 getframe 和电影的错误消息

Matlab上的闭环传递函数动画

标签: matlabcontrolsmatlab-figure

解决方案


您可以在循环中创建一系列情节并将每个情节捕获为一帧,然后使用电影功能播放电影。

一个例子如下:

% capture each plot as a frame and store the frames in M

for k = 1:16
    plot(fft(eye(k+16)))
    axis([-1 1 -1 1])
    M(k) = getframe;
end

% play recorded movie frames

figure
movie(M)

这是参考链接: https ://www.mathworks.com/help/matlab/creating_plots/record-animation-for-playback.html

至于你的情况,代码可以修改如下:

j = 0;
loops = 6;
Ini = 0;
End = 1; 

num = [9];
den = [1 2 9];
FT = tf(num, den);
CL = feedback(FT, 1);

figure;

while j < loops

  t = Ini:0.01:End; 

  hold on 
  step(CL, 'y', t);  
  hold off
  axis([0 10 0 1]);

  j = j+1;
  Ini = Ini+1;
  End = End+1;

  M(j) = getframe;

end

movie(M)

希望能帮助到你。


推荐阅读