MATLAB: Size problems with interp2

interp2MATLABmeshgrid

Hello,
I am working with data that I retrieved from remote sensing and would like to increase the spatial resolution of my data (to work alongside other data of different resolution).
My data matrix is a 2D matrix, where each x and y location yields a data value.
For example, I would like to increase the resolution of my matrix from 38×90 to 500×1000.
Here is what I tried:
—————————————-
[a b] = size(SST); %where SST is my 2D matrix containing data values…so then a would be 38 and b would be 90
x = 1:a; %This would serve as the x vector for SST data, x would be 1:38
y = 1:b; %This would serve as the y vector for SST data, y would be 1:90
XI = linspace(1,38,500); %This is the x resolution that I want YI = linspace(1,90,1000); %This is the y resolution that I want
[x y] = meshgrid(x,y); %create vector arrays [XI YI] = meshgrid(XI,YI); %create vector arrays
SST_hiRes = interp2(x,y,SST,XI,YI);
————————————————-
So basically I receive the following error:
"??? Error using ==> interp2 at 145 Matrices X and Y must be the same size as Z."
I am confused because I retrieved the size of these vectors from the "Z" vector directly…..any thoughts? I don't have the image toolbox unfortunately or I would use imresize.
Thanks for any input!
—Jimmy

Best Answer

The fix
[x y] = meshgrid(y,x); %create vector arrays
[XI YI] = meshgrid(YI,XI); %create vector arrays
You have x and y swapped, hence each is the transpose of the matrix you expect. You're confusing matrix notation (row,col) with cartesian coordinates (x,y). Also look at ndgrid for another solution/explanation.
And an FYI: You don't want to increase the resolution, you want to increase the sampling density.
Related Question