Plot overlapped on each other

31 ビュー (過去 30 日間)
Yanjika O
Yanjika O 2020 年 6 月 8 日
コメント済み: Yanjika O 2020 年 6 月 8 日
Hello,
I have this code for making animated plots in a loop and writing it into a video. However, when my second loop runs, the second plot appears to be plotted on top of the previous first plot.
filename='audioShockRecall.xlsx';
sheetname_kinovea=regexprep(filename,'.xlsx','');
conditioning=3;
col='B':'D';
x=1:1:509;
y1=10;
curve=animatedline('LineWidth',2,'Color','b');
set(gca, 'ylim',[0 500], 'xlim',[0 510],'OuterPosition',[0 0 1 1]);
grid on;
ylabel('\fontsize{14}Speed,px/s');
xlabel('\fontsize{14}Time,frame');
for i=1:conditioning
speed=xlsread(filename,sheetname_kinovea,strcat(col(i),':',col(i)));
figure(i);
for j=1:length(speed)
addpoints(curve,x(j),speed(j));
drawnow
F(j)=getframe(gcf);
title(strcat('Trajectory:Conditioning',(num2str(i))),'FontSize',16);
end
video=VideoWriter(strcat('Conditioning',num2str(i),'.mp4'),'MPEG-4');
video.FrameRate=30;
open(video);
writeVideo(video,F);
close(video);
end
How can I plot them all in separate figure? Or is there something wrong I wrote.

採用された回答

Image Analyst
Image Analyst 2020 年 6 月 8 日
Yes, that's what you told it to do. You first plotted an animated line in figure 1, then in your loop you said
figure(i);
so it reused figure #1 on the first iteration of your for loop. You should have just said
figure
and let it decide for itself what the number is.
And you forgot to attach 'audioShockRecall.xlsx' so we could run it.
  1 件のコメント
Yanjika O
Yanjika O 2020 年 6 月 8 日
Thanks!

サインインしてコメントする。

その他の回答 (1 件)

Yanjika O
Yanjika O 2020 年 6 月 8 日
For someone who ever needs it, I fixed the code as this way.
filename='audioShockRecall.xlsx';
sheetname_kinovea=regexprep(filename,'.xlsx','');
conditioning=3;
col='B':'D';
ylabel('\fontsize{14}Speed,px/s');
xlabel('\fontsize{14}Time,frame');
x=1:1:509;
for i=1:conditioning
clear y
y=xlsread(filename,sheetname_kinovea,strcat(col(i),':',col(i)));
figure(i);
set(gca, 'ylim',[0 500], 'xlim',[0 510],'OuterPosition',[0 0 1 1]);
curve=animatedline('LineWidth',2,'Color','b');
grid on;
for j=1:length(y)
addpoints(curve,x(j),y(j));
drawnow
F(j)=getframe(gcf);
title(strcat('Trajectory:Conditioning',(num2str(i))),'FontSize',16);
end
video=VideoWriter(strcat('Conditioning',num2str(i),'.mp4'),'MPEG-4');
video.FrameRate=29.97;
open(video);
writeVideo(video,F);
close(video);
close all
end

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by