animation : movie + comet in one figure (subplots)

3 次查看(过去 30 天)
Hi, I would like to plot two different animations in one figure. One the one hand I have a comet plot:
comet(data.pg{1,1});
And then I have an animation of a bar plot:
axis tight manual;
set(gca,'NextPlot','replaceChildren');
for i = 1:length(emg2{1,1})
extensors = [emg2{1,1}(i,1:5);emg2{1,1}(i,6:10);emg2{1,1}(i,11:15);emg2{1,1}(i,16:20);emg2{1,1}(i,21:25);emg2{1,1}(i,26:30);emg2{1,1}(i,31:35);emg2{1,1}(i,36:40);emg2{1,1}(i,41:45)];
bar3(abs(extensors))
F(i) = getframe;
end
movie(fig,F,1)
Now I want both animations to run at the same time and in the same figure but in subplots. I used a code but it doesn't work. Can anybody help ?
axis tight manual;
set(gca,'NextPlot','replaceChildren');
for i = 1:length(emg2{1,1})
subplot(1,2,1);
extensors = [emg2{1,1}(i,1:5);emg2{1,1}(i,6:10);emg2{1,1}(i,11:15);emg2{1,1}(i,16:20);emg2{1,1}(i,21:25);emg2{1,1}(i,26:30);emg2{1,1}(i,31:35);emg2{1,1}(i,36:40);emg2{1,1}(i,41:45)];
bar3(abs(extensors))
subplot(1,2,2);
comet(data.pg{1,1});
F(i) = getframe;
end
movie(F,1)
  4 个评论
N
N 2014-9-1
This is what I have so far, now both come in one figure but only the comet code runs, the bar3c does not change-animate
figure(1)
set(gca,'NextPlot','replaceChildren');
for i = 1:length(emg2)
subplot(2,1,1)
extensors = [emg2{1,1}(i,1:5);emg2{1,1}(i,6:10);emg2{1,1}(i,11:15);emg2{1,1}(i,16:20);emg2{1,1}(i,21:25);emg2{1,1}(i,26:30);emg2{1,1}(i,31:35);emg2{1,1}(i,36:40);emg2{1,1}(i,41:45)];
bar3c(abs(extensors))
subplot(2,1,2)
comet(data.pg2{1,1}(:,1))
F(i) = getframe;
end
movie(F,1)
Geoff Hayes
Geoff Hayes 2014-9-2
Have you stepped through the code to see what the length of emg2 is? Try doing this, and especially observe the behaviour of comet. This function is an animation, so as soon as you execute the statement
comet(data.pg2{1,1}(:,1))
the animation will begin and end before the next iteration of the for loop. So if the loop is supposed to iterate 100 times, then the same comet animation will play 100 times. If you want the comet to advance by one frame at each iteration (given that you have code to capture a frame), then you may have to rethink the use of comet in your code and manually advance the data.pg2 to the next "frame" or position.

请先登录,再进行评论。

回答(0 个)

类别

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