Plot overlapped on each other

31 次查看(过去 30 天)
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
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 CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by