Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
Keegan Carvalho
Keegan Carvalho le 4 Déc 2018
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.

Réponses (1)

KSSV
KSSV le 4 Déc 2018
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 commentaire
Keegan Carvalho
Keegan Carvalho le 4 Déc 2018
Modifié(e) : Keegan Carvalho le 4 Déc 2018
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.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by