필터 지우기
필터 지우기

How to plot different iterations with a time delay in for loop?

조회 수: 23 (최근 30일)
MT
MT 2015년 11월 29일
편집: MT 2015년 12월 2일
Hi,
I am having some trouble plotting different iterations with a time delay of for example one second in my loop:
load Data_SATP.mat
Days_SATP = Data_SATP([1:101:3131],[2]);
L_ATP = Data_SATP([2:101],[1]);
for j = 1:31
Sw = Data_SATP([(2+(101*(j-1))):(101*j)],[2]);
mat(j,:)=Sw
end
figure(2)
for k=(1:31);
plot(L_ATP,mat((1:31),:))
end
after which I fix the labels and axis. Now I get one plot of 31 graphs, but I would like to make the graphs appear one after each other in the same plot, preferably as an animated plot, but otherwise at least in the order of graph1, 1 second later graph2, etc.. I tried with pause(1), and I got it working once but after that I couldn't get it to work again after I changed some things, so advice on that is also welcome.
Thanks
[EDITED, Jan, Code formatted]

답변 (1개)

Jan
Jan 2015년 11월 29일
The body of the FOR loop over k does not depend ob k at all. I guess, that you want mat(k, :):
H = plot(L_ATP,mat(1, :))
for k = 2:31
pause(0.5);
set(H, 'YData', mat(k, :));
end
  댓글 수: 1
MT
MT 2015년 11월 29일
편집: MT 2015년 12월 2일
I have another question related to this, I used the advice you gave me and now a part of it consists of this:
clc;
close all;
clear all;
load CS1.mat
Days_SATP= CS1([1:21:189],[2]);
L_ATP= CS1([2:21],[1]);
for j=(1:9);
Sw= CS1([(2+(21*(j-1))):(21*j)],[2]);
mat(j,:)=Sw;
end
figure;
H = plot(L_ATP,mat(1, :));
title('Aqueous phase')
xlabel('Length (-)')
ylabel('Saturation')
axis([0 1 0 1])
for k = 2:9
pause(0.5);
set(H, 'YData', mat(k, :));
end
load CS2.mat
for j=(1:9);
Sw= CS2([(2+(21*(j-1))):(21*j)],[2]);
mat(j,:)=Sw;
end
figure;
H = plot(L_ATP,mat(1, :));
title('Aqueous phase')
xlabel('Length (-)')
ylabel('Saturation')
axis([0 1 0 1])
for k = 2:9
pause(0.5);
set(H, 'YData', mat(k, :));
end
which gives me two plots after each other for a different data set. How can I plot both the data of CS1 and CS2 simultaneously in one figure?
I tried the following, with different tries for the set(...) part, but I can't figure it out:
clc;
close all;
clear all;
load CS1.mat
load CS2.mat
Days_SATP= CS1([1:21:189],[2]);
L_ATP= CS1([2:21],[1]);
for j=(1:9);
Sw= CS1([(2+(21*(j-1))):(21*j)],[2]);
mat(j,:)=Sw;
Sw2= CS2([(2+(21*(j-1))):(21*j)],[2]);
mat2(j,:)=Sw2;
end
figure;
H = plot(L_ATP,mat(1, :));
H2 = plot(L_ATP,mat2(1, :));
title('Aqueous phase')
xlabel('Length (-)')
ylabel('Saturation')
axis([0 1 0 1])
for k = 2:9
pause(0.5);
set(H, 'YData', mat(k, :),H2,'YData', mat2(k,:));
end
Regards,
Martin

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by