%%%%%%%%%%%%%西安市2013-4-20——2013-5-20数据%%%%%%%%%%%%%%%
close all
clc
clear
x=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31];
y=[64 111 156 155 135 113 78 104 85 77 42 83 56 63 85 81 92 99 80 40 56 43 48 63 53 82 92 52 33 66 101];
z=[19 18 15 26 27 29 31 31 32 25 24 26 27 32 28 23 21 24 22 25 28 33 35 35 34 28 26 22 29 32 33];
pm10=[89 131 200 217 248 166 269 305 234 47 77 184 135 179 164 125 124 131 105 96 130 118 133 166 103 177 139 76 72 175 182];
x=x‘;%日期
y=y‘;%PM2.5数据
z=z‘;%最高温度
pm10=pm10‘;%PM10数据
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%数据的拟合
[p0,s0]=polyfit(x,y,15);%n表示采用n阶多项式拟合
[p1,s1]=polyfit(x,z,15);
[p2,s2]=polyfit(x,pm10,18);
y0=polyval(p0,x);
y1=polyval(p1,x);
y2=polyval(p2,x);
plot(x,y,‘r*‘);%对原始数据进行描点
hold on;
plot(x,z,‘go‘);
hold on;
plot(x,pm10,‘bo‘);
hold on;
plot(x,y0,‘r‘);%绘制拟合曲线
plot(x,y1,‘g‘);
plot(x,y2,‘b‘);
xlabel(‘x日期‘);
ylabel(‘yPM10‘);
legend(‘pm2.5原始数据‘,‘最高温度原始数据‘,‘PM10原始数据‘,‘pm2.5拟合曲线‘,‘最高温度拟合曲线‘,‘PM10拟合曲线‘)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%拟合完毕
title(‘西安市2013-4-20——2013-5-20数据‘);
rpm2d5=corrcoef(y0,y)
r12=corrcoef(y1,y2)
%axis square;%让格式变为方形