Interpolation or resize or what??

Can you change the dimensions (and thus the resolutions) of multiple matrices of various dimensions? I have {n} matrices of different lon/lat, each of SST/Precip correlations per gridpoint, that I must change to matching dimensions (lon/lat) to correlate together.
There must be a way, perhaps using interp2, but I cannot verify this. My worry is that any interpolation or resize will compromise the correlation values when making dimensions smaller. I cannot find enough information about any process to verify what will be done to the values of the changing matrices.
I have 46 matrices (in a 46x1 array) of 46 sst/precip correlations with some various lat/lon dimensions (for example, 144x196, 48x96....and so on). In order to correlate all of them together, I have to interpolate or resize, for lack of the right word, most of them to the dimension of the smallest one, 48x96. I just cannot find the right way to do this anywhere. interp2 requires a z value, which in this case could be my correlation values, but I do not know how to call on this. I also have the matrices stored in a vector array because they have been created from a for-loop (ie. ModelCorr{k}, k= 1:46 climate models), which further complicates matters. Can these matrices in the vector array be converted with a similar for-loop process?
Can anyone help?

댓글 수: 2

Jan
Jan 2017년 8월 2일
편집: Jan 2017년 8월 2일
The question is not clear. Sentences like "I have 46 matrices (in a 46x1 array) of 46 sst/precip correlations with some various lat/lon dimensions (for example, 144x196, 48x96....and so on)" are more confusing than a small piece of code which creates example data by rand().
Chad Greene
Chad Greene 2017년 8월 2일
As I understand the question, I think interp2 is the way to go, but I would interpolate to the larger (higher resolution) grid. If you interpolate a high-res grid down to a low resolution, you introduce the possibility of aliasing, but you can always interpolate a coarse grid to higher resolution without loss of information. Just remember that smaller grid cells doesn't always mean the underlying data are higher resolution.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2017년 8월 2일
편집: Jan 2017년 8월 4일

1 개 추천

I guess boldly:
C = {rand(144,196), rand(48,96), rand(113, 204)};
S1 = min(cellfun('size', C, 1));
S2 = min(cellfun('size', C, 2));
D = cell(size(C));
for k = 1:numel(C)
siz = size(C{k});
% [EDITED, X and Y swapped]
D{k} = interp2(C{k}, linspace(1, siz(2), S2).', linspace(1, siz(1), S1));
end
Now D contains all matrices scaled to the minimal size of the matrices stored in C.

댓글 수: 3

Cory Phillips
Cory Phillips 2017년 8월 2일
Jan, thanks for this translation. I will try it. It makes sense this way.
Cory Phillips
Cory Phillips 2017년 8월 2일
편집: Cory Phillips 2017년 8월 2일
So after trying a bit, it appears the above code succeeds at resizing the matrices (awesome!), but I think the last line should invert the two linspace functions.
Jan
Jan 2017년 8월 4일
@Cory: You are right, the dimensions have been swapped.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2017년 8월 2일

댓글:

Jan
2017년 8월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by