Size problems with interp2
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
2011-7-20
You're welcome!
If this worked for you, please accept this answer to mark this thread closed.
Thanks!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!