Size problems with interp2

4 visualizzazioni (ultimi 30 giorni)
James
James il 19 Lug 2011
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 38x90 to 500x1000.
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

Risposta accettata

Sean de Wolski
Sean de Wolski il 20 Lug 2011
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.
  3 Commenti
Sean de Wolski
Sean de Wolski il 20 Lug 2011
You're welcome!
If this worked for you, please accept this answer to mark this thread closed.
Thanks!
James
James il 20 Lug 2011
done and done.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Multidimensional Arrays in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by