欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Matlab处理气象数据(七)分段趋势线的做法

程序员文章站 2022-07-14 11:49:17
...

退耕还林工程自1999年起开始实施,土地利用的改变会影响区域气候。为了研究区域气候的变化,需要对退耕前和退耕后作对比。

在matlab中,需要对1999年前和后分别作出趋势线,这种趋势线可以采用matlab的趋势拟合函数作出。

多项式函数拟合:

a=polyfit(xdata,ydata,n)

其中n表示多项式的最高阶数,xdata,ydata为将要拟合的数据,它是用数组的方式输入。输出参数a为拟合多项式 y=a1xn+…+anx+a n+1的系数。多项式在x处的值y可用下面程序计算,

y=polyval(a,x,m)

线性:m=1;二次:m=2;…
polyfit的输出是一个多项式系数的行向量。为了计算在xi数据点的多项式值,调用MATLAB的函数polyval

%画两套数据1981-2013年平均气温差值的分段趋势线
load('Tem1.mat');
load('Tem2.mat');
DT=Tem2-Tem1;
DT0=DT;
DT0(1:2)=[];
DT1=DT0;
DT1(20:33)=[];
DT2=DT0;
DT2(1:19)=[];

x1=1:19;
A=polyfit(x1,DT1,1);
Z=polyval(A,x1);
plot(x1,DT1,'r.-',x1,Z,'b--','linewidth',2);
hold on
x2=20:33;
B=polyfit(x2,DT2,1);
Z=polyval(B,x2);
plot(x2,DT2,'r.-',x2,Z,'b--','linewidth',2);
plot (DT0-detrend(DT0),'b--','linewidth',2);%添加趋势线
xlabel('Year');ylabel('Temperarure(\circC)');
set(gca,'xtick',[ 5 10 15 20 25 30],'xticklabel',{'1985','1990','1995','2000','2005','2010'});
set(gca, 'FontSize',10,'FontWeight','Bold','tickdir','out') %设置标注为10号字、加粗、标记线向外
h=xlabel('Year'); %设置x轴名称
set(h, 'FontSize',10,'FontWeight','Bold')
h=ylabel('Temperarure(\circC)'); %设置y轴名称
set(h, 'FontSize',10,'FontWeight','Bold') 
xlim([1 33])%x轴范围锁定为1~33
box off %去掉外框
hold off

得到下图:
Matlab处理气象数据(七)分段趋势线的做法

1999年前、后平均温度差值趋势线

输出A的值为[0.013908553308574,0.739492012915606],B的值为[0.003623950006347,1.164911670778532]。

最高、最低温度差值计算方法与之类似。

%画两套数据1981-2013年最高气温差值的趋势线
load('Temmax1.mat');
load('Temmax2.mat');
DTmax=Temmax2-Temmax1;
DTmax0=DTmax;
DTmax0(1:2)=[];
DTmax1=DTmax0;
DTmax1(20:31)=[];
DTmax2=DTmax0;
DTmax2(1:19)=[];
 
x1=1:19;
A=polyfit(x1,DTmax1,1);
Z=polyval(A,x1);
plot(x1,DTmax1,'r.-',x1,Z,'b--','linewidth',2);
hold on
x2=20:31;
B=polyfit(x2,DTmax2,1);
Z=polyval(B,x2);
plot(x2,DTmax2,'r.-',x2,Z,'b--','linewidth',2);
plot (DTmax0-detrend(DTmax0),'b--','linewidth',2);%添加趋势线
xlabel('Year');ylabel('Temperarure(\circC)');
set(gca,'xtick',[ 5 10 15 20 25 30],'xticklabel',{'1985','1990','1995','2000','2005','2010'});
set(gca, 'FontSize',10,'FontWeight','Bold','tickdir','out') %设置标注为10号字、加粗、标记线向外
h=xlabel('Year'); %设置x轴名称
set(h, 'FontSize',10,'FontWeight','Bold')
h=ylabel('Temperarure(\circC)'); %设置y轴名称
set(h, 'FontSize',10,'FontWeight','Bold') 
xlim([1 33])%x轴范围锁定为1~33
box off %去掉外框
hold off

Matlab处理气象数据(七)分段趋势线的做法

1999年前、后最高温度差值趋势线

输出A的值为[0.009736153700025,1.554127661596744],B的值为[-0.015314570766371,2.394812735494515]。

%画两套数据1981-2013年最低气温差值的趋势线
load('Temmin1.mat');
load('Temmin2.mat');
DTmin=Temmin2-Temmin1;
DTmin0=DTmin;
DTmin0(1:2)=[];
DTmin1=DTmin0;
DTmin1(20:31)=[];
DTmin2=DTmin0;
DTmin2(1:19)=[];
 
x1=1:19;
A=polyfit(x1,DTmin1,1);
Z=polyval(A,x1);
plot(x1,DTmin1,'r.-',x1,Z,'b--','linewidth',2);
hold on
x2=20:31;
B=polyfit(x2,DTmin2,1);
Z=polyval(B,x2);
plot(x2,DTmin2,'r.-',x2,Z,'b--','linewidth',2);
plot (DTmin0-detrend(DTmin0),'b--','linewidth',2);%添加趋势线
xlabel('Year');ylabel('Temperarure(\circC)');
set(gca,'xtick',[ 5 10 15 20 25 30],'xticklabel',{'1985','1990','1995','2000','2005','2010'});
set(gca, 'FontSize',10,'FontWeight','Bold','tickdir','out') %设置标注为10号字、加粗、标记线向外
h=xlabel('Year'); %设置x轴名称
set(h, 'FontSize',10,'FontWeight','Bold')
h=ylabel('Temperarure(\circC)'); %设置y轴名称
set(h, 'FontSize',10,'FontWeight','Bold') 
xlim([1 33])%x轴范围锁定为1~33
box off %去掉外框
hold off

Matlab处理气象数据(七)分段趋势线的做法

1999年前、后最低温度差值趋势线

输出A的值为[0.019171811945648,0.963068491579686],B的值为[0.022148294337837,1.030687894465706]。


相关链接:
Matlab处理气象数据——目录

相关标签: matlab 气象