Why isn't animatedline showing a line plot?

조회 수: 5 (최근 30일)
Rebecca Ward
Rebecca Ward 2021년 3월 9일
댓글: Rebecca Ward 2021년 3월 9일
Hi, I'm trying to plot an animation with 4 subplots. It is working fine except that the plots only show up if I put in a marker, not just a line.
Here is the code - can anyone advise as to how to get lines to show?
load dfRH;
load xxout;
seq = 1:6:1418;
SimT = xxout(seq,3)-273.15;
ACH = csvread('ACH_AO_1000.csv');
IAS = csvread('IAS_AO_1000.csv');
ACH_mean = mean(ACH,2)*9+1;
IAS_mean = mean(IAS,2)*0.75+0.1;
figure('WindowStyle','docked');
for k = 1:100
subplot(1,4,1)
title('Relative Humidity Data');
xlabel('timestep');
ylabel('Relative Humidity (%)');
h1 = animatedline('Marker','.','Color','b');
xlim([1,100])
ylim([0,100])
x = k;
y1 = dfRH(k,1)*100;
addpoints(h1,x,y1);
pause(0.05)
drawnow
subplot(1,4,2)
title('Ventilation Rate');
xlabel('timestep');
ylabel('Ventilation Rate (ACH)');
h2 = animatedline('Marker','o','Color','k');
xlim([1,100])
ylim([0,10])
y2 = ACH_mean(k);
addpoints(h2,x,y2);
pause(0.05)
drawnow
subplot(1,4,3)
title('Internal Air Speed');
xlabel('timestep');
ylabel('Internal Air Speed (m/s)');
h3 = animatedline('Marker','x','Color','k');
xlim([1,100])
ylim([0,1])
y3 = IAS_mean(k);
addpoints(h3,x,y3);
pause(0.05)
drawnow
subplot(1,4,4)
title('Temperature');
xlabel('timestep');
ylabel('Temperature (^oC)');
h4 = animatedline('Marker','.','Color','r');
xlim([1,100])
ylim([0,30])
y4 = SimT(k);
addpoints(h4,x,y4);
pause(0.05)
drawnow
end

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 3월 9일
편집: Cris LaPierre 2021년 3월 9일
I think the animatedline commands should be outside the for loop. In fact, everything except for the addpoints related code should be outside the for loop.
Here's a simple example.
ax1 = subplot(1,4,1);
h1 = animatedline(ax1);
xlim([1,100])
ylim([0,100])
title('Ventilation Rate');
xlabel('timestep');
ylabel('Ventilation Rate (ACH)');
ax2 = subplot(1,4,2);
h2 = animatedline(ax2);
xlim([1,100])
ylim([0,-100])
title('Ventilation Rate');
xlabel('timestep');
ylabel('Ventilation Rate (ACH)');
x = 1:100;
y = 50*(sin(x)+1);
for k = 1:100
ax1=subplot(1,4,1);
addpoints(h1,x(k),y(k));
drawnow
subplot(1,4,2)
addpoints(h2,x(k),-y(k));
drawnow
end
  댓글 수: 1
Rebecca Ward
Rebecca Ward 2021년 3월 9일
Fantastic, thankyou for your help Cris this works perfectly.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by