Hi, How can I connect avg points?
DAN=[ 19.83 1000.7;
16.72 997.2;
18.47 1012.9;
21.06 987.3;
17.99 1005.1;
18.25 993.6;
18.96 1003.8;
20.73 998.2;
17.97 1005.9;
16.99 1001.2]
x=[2010:2019];
press=(DAN(:,2));
temp=(DAN(:,1));
avg_press=mean(press)
avg_temp=mean(temp)
subplot(2,1,1);
plot(x,press,x,avg_press)
subplot(2,1,2);
plot(x,temp,xavg_temp)
Thanks!

 Réponse acceptée

Stephan
Stephan le 10 Nov 2020
Modifié(e) : Stephan le 10 Nov 2020

1 vote

You might want to use the yline function:
DAN=[ 19.83 1000.7;
16.72 997.2;
18.47 1012.9;
21.06 987.3;
17.99 1005.1;
18.25 993.6;
18.96 1003.8;
20.73 998.2;
17.97 1005.9;
16.99 1001.2]
x=[2010:2019];
press=(DAN(:,2));
temp=(DAN(:,1));
avg_press=mean(press)
avg_temp=mean(temp)
subplot(2,1,1);
plot(x,press,'-b')
yline(avg_press,'--b')
subplot(2,1,2);
plot(x,temp,'-r')
yline(avg_temp,'--r')
alternative (if you have an earlier release then R2018b) you could use:
DAN=[ 19.83 1000.7;
16.72 997.2;
18.47 1012.9;
21.06 987.3;
17.99 1005.1;
18.25 993.6;
18.96 1003.8;
20.73 998.2;
17.97 1005.9;
16.99 1001.2]
x=[2010:2019];
press=(DAN(:,2));
temp=(DAN(:,1));
avg_press=mean(press)
avg_temp=mean(temp)
subplot(2,1,1);
plot(x,press,'-b',x,repmat(avg_press,1,numel(x)),'--b')
subplot(2,1,2);
plot(x,temp,'-r',x,repmat(avg_temp,1,numel(x)),'--r')

1 commentaire

Mateusz Tomczak
Mateusz Tomczak le 10 Nov 2020
Modifié(e) : Mateusz Tomczak le 10 Nov 2020
alternative:
DAN=[ 19.83 1000.7;
16.72 997.2;
18.47 1012.9;
21.06 987.3;
17.99 1005.1;
18.25 993.6;
18.96 1003.8;
20.73 998.2;
17.97 1005.9;
16.99 1001.2];
x=[2010:2019];
press=(DAN(:,2));
temp=(DAN(:,1));
avg=ones(1,10)
avg_press=mean(press)*avg
avg_temp=mean(temp)*avg
subplot(2,1,1);
plot(x,press,'-b',x,avg_press,'--')
subplot(2,1,2);
plot(x,temp,'-r',x,avg_temp,'--')
clc

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by