Interpolation or resize or what??
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Jan
el 2 de Ag. de 2017
Editada: Jan
el 2 de Ag. de 2017
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
el 2 de Ag. de 2017
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.
Respuestas (1)
Jan
el 2 de Ag. de 2017
Editada: Jan
el 4 de Ag. de 2017
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 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!