How to plot regression coefficients on a map?

I have attached a zipped netcdf file ('ssh.nc'). I wanted to do a corellation test between variables, 'zos' and 'bottomT' which have the following dimensions of longitude,latitude,time. After this I wanted to plot the correlation coefficients on a map.
I tried the following code but get an error about the rows. I find it weird since the dimensions are the same.
>> lat = ncread('ssh.nc','latitude');
>> lon = ncread('ssh.nc','longitude');
>> ssh = ncread('ssh.nc','zos');
>> t = ncread('ssh.nc','bottomT');
>> nx=length(lon);
>> ny=length(lat);
>> for i=1:nx
for j=1:ny
[r,s] = corr(t,ssh(i,j,:));
rxy(i,j)=r;
sxy(i,j)=s;
end
end
I get the error:
Error using corr (line 106)
X and Y must have the same number of rows.
I also tried correlate, corr2 but get errors.
Would be grateful to receive help in this, preferably with the correct codes, since I am going wrong somehere. I also want to know what's wrong in the above.

 Respuesta aceptada

KSSV
KSSV el 20 de Dic. de 2018
Editada: KSSV el 20 de Dic. de 2018
YOu need to calculate the coeffecenits for 3D matrix.
lat = ncread('ssh.nc','latitude');
lon = ncread('ssh.nc','longitude');
ssh = ncread('ssh.nc','zos');
t = ncread('ssh.nc','bottomT');
nx=length(lon);
ny=length(lat);
rxy = zeros(nx,ny) ;
sxy = zeros(nx,ny) ;
for i=1:nx
for j=1:ny
[r,s] = corr(squeeze(t(i,j,:)),squeeze(ssh(i,j,:)));
rxy(i,j)=r;
sxy(i,j)=s;
end
end

7 comentarios

Keegan Carvalho
Keegan Carvalho el 20 de Dic. de 2018
Thanks KSSV, It worked. However, the result is in the form of a film. Probably because it shows the correlations for each time value.
How do I get the R2 value for the entire time as an average (just one value for the entire time range)? So that I can store it as an image.
Regards
KSSV
KSSV el 20 de Dic. de 2018
Editada: KSSV el 20 de Dic. de 2018
Hey I relaized that..my last answer is irelevant to your question...now I have modified the answer..I guess this works according to your old code.
KSSV
KSSV el 20 de Dic. de 2018
rxy and sxy are matrices......what you want exactly? The old code or the one you psoted int he question?
Keegan Carvalho
Keegan Carvalho el 20 de Dic. de 2018
Editada: Keegan Carvalho el 20 de Dic. de 2018
Sorry for the confusion; ignore that. Since I got two matrices rxy and sxy, I used the code to create the map:
pcolor(lon,lat,rxy) ;
shading interp
colorbar
drawnow
Also tried for sxy.
But am a little confused. Which one should I plot? rxy OR sxy?
Because the values are different in both matrices
Off course rxy. Read the docmumentation. You can simply use corr like below:
for i=1:nx
for j=1:ny
r = corr(squeeze(t(i,j,:)),squeeze(ssh(i,j,:)));
rxy(i,j)=r;
end
end
Keegan Carvalho
Keegan Carvalho el 20 de Dic. de 2018
Thank you KSSV :)
Appreciate your continued guidance.
Aristo Pacino
Aristo Pacino el 20 de Jul. de 2021
Hi, @KSSV, I have used the same code for calculating correlation coefficient at grid points using the above code but I am getting NaN values. Please find attached data.
Some specification:
  1. Lat =0:10:360
  2. Lon = -180:10:180
  3. t and ssh are 37-by-37 matrix

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Distribution Plots en Centro de ayuda y File Exchange.

Preguntada:

el 20 de Dic. de 2018

Comentada:

el 20 de Jul. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by