Size problems with interp2

4 ビュー (過去 30 日間)
James
James 2011 年 7 月 19 日
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

採用された回答

Sean de Wolski
Sean de Wolski 2011 年 7 月 20 日
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 件のコメント
Sean de Wolski
Sean de Wolski 2011 年 7 月 20 日
You're welcome!
If this worked for you, please accept this answer to mark this thread closed.
Thanks!
James
James 2011 年 7 月 20 日
done and done.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by