Plot overlapped on each other
조회 수: 13 (최근 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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/312080/image.png)
How can I plot them all in separate figure? Or is there something wrong I wrote.
댓글 수: 0
채택된 답변
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개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!