How to find the coefficient of determination (R2) between 2 variables in netcdf?

3 次查看(过去 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.

回答(1 个)

KSSV
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
  1 个评论
Keegan Carvalho
Keegan Carvalho 2018-12-4
编辑:Keegan Carvalho 2018-12-4
Thanks KSSV, but I wanted to find it spatially.
Btw, I tried the above code but unfortunately did not suceed since I didn't have the Deep Learning Toolbox.
However, I would like to know how to do it spatially.

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by