相關(guān)分析在科研過(guò)程中常常會(huì)碰到,表征了一種兩個(gè)因素間的相關(guān)程度,其值的大小只能說(shuō)明相關(guān)性的強(qiáng)弱。
比如當(dāng)我們有2000-2015年的NPP數(shù)據(jù)和2000-2015年的降水?dāng)?shù)據(jù)時(shí),我們想查看兩者在空間上隨時(shí)間變化的
相關(guān)性。本文以產(chǎn)水和NPP為例進(jìn)行說(shuō)明
具體代碼如下:
%authour@yinlichang3064@163.com
%將兩者多年的數(shù)據(jù)放在三個(gè)不同的矩陣中
nppsum=zeros(3587*4642,16);
for year=2000:2015
filename=strcat('F:\課題項(xiàng)目\data\',int2str(year),'npp.tif');
data=importdata(filename);
data=reshape(data,3587*4642,1);
nppsum(:,year-1999)=data;
end
wcsum=zeros(3587*4642,16);
for year=2000:2015
filename=strcat('F:\課題項(xiàng)目\data\',int2str(year),'water_yield.tif');
data=importdata(filename);
data=reshape(data,3587*4642,1);
wcsum(:,year-1999)=data;
end
%相關(guān)性和顯著性
npp_wc_xgx=zeros(3587,4642);
npp_wc_p=zeros(3587,4642);
for i=1:length(nppsum)
npp=nppsum(i,:);
if min(npp)>0 %注意這里的NPP的有效范圍是大于0,如果自己的數(shù)據(jù)有效范圍有小于0的話(huà),則可以不用加這個(gè)
wc=wcsum(i,:);
[r2,p2]=corrcoef(npp,wc);
npp_wc_xgx(i)=r2(2);
npp_wc_p(i)=p2(2);
end
end
filename5='F:\result\npp_wc相關(guān)性.tif';
filename6='F:\npp_wc顯著性.tif';
[a,R]=geotiffread('F:\項(xiàng)目\data\2002water_yield.tif');%先導(dǎo)入投影信息
info=geotiffinfo('F:\項(xiàng)目\data\2002water_yield.tif');
%%輸出圖像
geotiffwrite(filename5,npp_wc_xgx,R,'GeoKeyDirectoryTag',info.GeoTIFFTags.GeoKeyDirectoryTag);
geotiffwrite(filename6,npp_wc_p,R,'GeoKeyDirectoryTag',info.GeoTIFFTags.GeoKeyDirectoryTag);
如果自己的數(shù)據(jù)中存在負(fù)值,不想加限制條件的話(huà),可以用下面的代碼,但運(yùn)行效率會(huì)降低,代碼如下
更多需求,請(qǐng)查看個(gè)人介紹