How to find the coefficient of determination (R2) between 2 variables in netcdf?
조회 수: 2 (최근 30일)
이전 댓글 표시
I have attached a zipped netcdf file ('ssh.nc').
I wanted to do a corellation test (OR to find the R2 value between two variables). The two variables are 'zos' and 'bottomT' which have the following dimensions of longitude,latitude,time. After this I wanted to plot a map so I can find out in which regions the correlation is high/low.
I tried to use ncread and extract grid-by-grid values but it is time- consuming and I might be prone to making errors. Is there any code that can find the correlation between two variables?
Would be grateful for assistance in this.
댓글 수: 0
답변 (1개)
KSSV
2018년 12월 4일
It depends whether you want to find it spatially or temporally. I feel temporal regression is the one you are looking for. Check this code:
ncfile = 'ssh.nc' ;
A = ncread(ncfile,'zos') ;
B = ncread(ncfile,'bottomT') ;
[nx,ny,nt] = size(A) ;
R = zeros(nx,ny) ;
for i = 1:nx
for j = 1:ny
Ai = squeeze(A(i,j,:)) ;
Bi = squeeze(B(i,j,:)) ;
R(i,j) = regression(Ai',Bi')^2 ;
end
end
참고 항목
카테고리
Help Center 및 File Exchange에서 NetCDF에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!