Plot overlapped on each other

37 visualizaciones (últimos 30 días)
Yanjika O
Yanjika O el 8 de Jun. de 2020
Comentada: Yanjika O el 8 de Jun. de 2020
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.

Respuesta aceptada

Image Analyst
Image Analyst el 8 de Jun. de 2020
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.

Más respuestas (1)

Yanjika O
Yanjika O el 8 de Jun. de 2020
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

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by