简体   繁体   English

通过多个2D Matlab图进行动画处理

[英]Animate through multiple 2D Matlab plots

I have multiple 2D line plots in Matlab (they represent some wave moving through space). 我在Matlab中有多个2D线图(它们表示在空间中移动的某些波)。 Each plot represents the wave at some time t. 每个图表示在某个时间t处的波浪。 I want to animate through these plots (ie show the first plot for a fraction of a second, then show the next one, and the next, etc. I want to loop back to the beginning once it reaches the end time) to show the time evolution of the system. 我想对这些图进行动画处理(例如,将第一个图显示几分之一秒,然后显示下一个图,然后显示下一个图,依此类推。一旦到达结束时间,我想循环回到起始处)以显示系统的时间演变。 surf and mesh don't really do what I want since it is too difficult to see the changes with the number of time steps I have. 冲浪和网格并没有真正实现我想要的功能,因为很难看到随着时间步长的变化。 Is there a way to do this in Matlab? 有没有办法在Matlab中做到这一点?

I assume with "2d-line" you mean a 2d-plot. 我假设使用“ 2d线”表示2d图。 This is done by the plot -function, so there is no need of surf or mesh . 这是通过plot函数来完成的,因此不需要surfmesh Sorry, when I got you wrong. 对不起,我误会你的意思。

The following code does what I think you asked for: 以下代码可以满足您的要求:

% Generate some propagating wave
n = 20;
t = linspace(0,10,100);
x = cell(1,n);
for i = 1:n
    x{i} = (1-abs(i/n-0.4))*sin(t+i*0.2);
end

% Create frames
figure;
for i = 1:length(x)
   clf;
   plot(t,x{i});
   ylim([-1,1]);
   myFrames(i) = getframe;  %#ok<SAGROW>
end

% Show movie
figure;
movie(myFrames,2,2);    % frames, repetitions, frames per second

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM