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!

 Akzeptierte Antwort

Stephan
Stephan am 10 Nov. 2020
Bearbeitet: Stephan am 10 Nov. 2020

1 Stimme

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 Kommentar

Mateusz Tomczak
Mateusz Tomczak am 10 Nov. 2020
Bearbeitet: Mateusz Tomczak am 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by