Interpolating one dimension in 4-th dimensional matrix?

4 Ansichten (letzte 30 Tage)
Robert
Robert am 27 Mai 2011
Kommentiert: Argho Datta am 13 Jun. 2019
Hi Matlab users.
I have a matrix which is like that (132,238,35,6) this is for longitude, latitude, depth and time. And I want to interpolate the depth so I will have 70 instead of 35. The problem is that I don't know how to properly do that because if I try to call the depth like that: (1,1,:,1) I will have only the one corresponding first longitude and first latitude, not the entire depth. Also If I call like that: (:,:,35,:) the interpolation function don't work. Is there any way to interpolate a 4-th dimensional matrix so I will obtain 70 depths instead of 35?
Thank you,
Robert.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 27 Mai 2011
interpn(Longs,Lats,Depths,Times,TheMatrix,Longs,Lats,NewDepths,Times)
Note: if you do not want to extrapolate the most obvious new depths would include the ones half-way between the old depths, which would lead to 69 output depths, not 70.
  1 Kommentar
Argho Datta
Argho Datta am 13 Jun. 2019
Hi, sorry to dig this up, but what does the argmuent NewDepths refer to? Thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Jan
Jan am 27 Mai 2011
Do you want a linear interpolation? Then you can do it manually also:
data = rand(132,238,35,6);
% 70 values between 1 and 35:
v = linspace(1, 35, 70)
% Indices of left and right slice of the array:
t = floor(v);
p = v - t;
% Consider edge at the end:
t(end) = t(end) - 1;
p(end) = 1;
p = reshape(p, 1, 1, []);
R = bsxfun(@times, data(:, :, t, :), (1 - p)) + ...
bsxfun(@times, data(:, :, t+1, :), p);

Robert
Robert am 27 Mai 2011
Thank you both guys, both variants are working just fine.
Thanks again.

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by