hello everyone, i have this urgent problem

1 次查看(过去 30 天)
hello everyone, i have a problem about animating multi-sin waves,each of them is starts with different time(ex:sin1 starts with 0,sin2 starts with 1...etc),besides,the animation speed of them r different,can someone help me out,please? i really need to figure this out for my thesis ><
  3 个评论
Chia Ho Hsu
Chia Ho Hsu 2020-7-6
编辑:Walter Roberson 2020-7-6
like this, but i need the amplitude and the moving speed of 'O' and speed can be controllable,this is my code,i cant make it plot like the above photo i showed you:
clc;clear all;
t=0:0.1:100;
t2=1:0.5:100;
y=sin(t);
y2=sin(t2);
for k=1:length(t)
plot(t(k),y(k),'X')
hold on
plot(t2(k),y2(k),'O')
hold on
plot(t(1:k),y(1:k))
hold on
plot(t2(1:k),y2(1:k))
hold on
axis([0 100 -1 1])
grid on
xlabel('t')
ylabel('y')
legend('servo degree', 'servo degree','servo 1','servo 2')
pause(0.1)
if k~=length(t)
clf
end
if k~=length(t2)
clf
end
end
Walter Roberson
Walter Roberson 2020-7-6
N = 1000;
t2 = linspace(0, 100, N);
t = t/5;
Do not use t = linspace(0,100) and then t2=t1*5 because if you do then t2 will escape the boundaries of the plot.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2020-7-6
编辑:Walter Roberson 2020-7-6
The other main possibility is to use timers, one for each simulation, with the timers firing each time each simulation is to advance to the next sample.

更多回答(1 个)

Steven Lord
Steven Lord 2020-7-6
t = 0:360;
h1 = animatedline('LineStyle', '-', 'Color', 'k');
h2 = animatedline('LineStyle', '--', 'Color', 'c');
axis([0 450 -1 1]);
for k = 1:numel(t)
addpoints(h1, t(k), sind(t(k)));
addpoints(h2, t(k)+90, sind(t(k)));
pause((10/360))
end
While in this example I called addpoints on each of the animatedline objects at each iteration of the for loop, you could update each line only at certain iterations if you so desired.

类别

Help CenterFile Exchange 中查找有关 Animation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by