最小二乘法实例应用
程序
%% 调用颜色;
cmap=colormore_17(2:6);line=1.8;line2=1.5;
num=17
% 画图
figure;
h1=plot(sst_alab,'-o','linewidth',line,...
'color',cmap(1,:),'MarkerFaceColor',cmap(1,:));%净热通量
hold on
plt_h=fplot(alab_yy);
set(plt_h,'color',cmap(1,:),'linewidth',line2)
hold on
h2=plot(sst_bob,'-o','linewidth',line,...
'color',cmap(2,:),'MarkerFaceColor',cmap(2,:));%净热通量
hold on
plt_h=fplot(bob_yy);
set(plt_h,'color',cmap(2,:),'linewidth',line2)
hold on
h3=plot(sst_east,'-o','linewidth',line,...
'color',cmap(3,:),'MarkerFaceColor',cmap(3,:));%净热通量
hold on
plt_h=fplot(east_yy);
set(plt_h,'color',cmap(3,:),'linewidth',line2)
hold on
h4=plot(sst_west,'-o','linewidth',line,...
'color',cmap(4,:),'MarkerFaceColor',cmap(4,:));%净热通量
hold on
plt_h=fplot(west_yy);
set(plt_h,'color',cmap(4,:),'linewidth',line2)
hold on
h5=plot(sst_sumali,'-o','linewidth',line,...
'color',cmap(5,:),'MarkerFaceColor',cmap(5,:));%净热通量
hold on
plt_h=fplot(sumali_yy);
set(plt_h,'color',cmap(5,:),'linewidth',line2)
hold on
axis([1 40 23 31]);
leg_h=legend([h1,h2,h3,h4,h5],'阿拉伯海区','孟加拉湾区','东印度洋暖池区','西印度洋暖池区','索马里沿岸区','orientation','horizontal');
set(leg_h,'position',[0.13 0.48 0.8 0.2],'fontsize',12,'fontname','宋体');
legend boxoff;
box off
title('自编最小二乘法线性趋势')
text(40.5,31,['K\_west=',num2str(round(west_c(2),2))])
text(40.5,30.5,['R^2\_west=',num2str(round(west_wucha,2))])
text(40.5,29.5,['K\_east=',num2str(round(east_c(2),2))])
text(40.5,29,['R^2\_east=',num2str(round(east_wucha,2))])
text(40.5,26.5,['K\_alab=',num2str(round(alab_c(2),2))])
text(40.5,26,['R^2\_alab=',num2str(round(alab_wucha,2))])
text(40.5,25.5,['K\_bob=',num2str(round(bob_c(2),2))])
text(40.5,25,['R^2\_bob=',num2str(round(bob_wucha,2))])
text(40.5,24.5,['K\_sumali=',num2str(round(sumali_c(2),2))])
text(40.5,24,['R^2\_sumali=',num2str(round(sumali_wucha,2))])
alpha(1)
set(gca,'fontsize',12,'fontweight','bold','xtick',[1:2:41],'xticklabel',[1979:2:2018],'fontname','time news roman');
xlabel(['\fontname{宋体}时间(年)', sprintf('\n'),'\fontname{Times New Roman}time( year )'],'fontsize',15,'fontweight','bold');
ylabel(['\fontname{宋体}海表面温度', sprintf('\n'),'\fontname{Times New Roman}sea surface temperature( °C)'],'fontsize',15,'fontweight','bold');
set(gcf,'position',[50,50,1100,500],'color','w');
export_fig(['自编最小二乘法线性趋势',num2str(num),'.png'],'-r300')