How to interpolate 2 dimensions of a 4D array ?

조회 수: 5 (최근 30일)
bhakti
bhakti 2023년 12월 5일
댓글: bhakti 2023년 12월 8일
I have a 4D array which represents velocity(ocean currents) in a region, and I have to interpolate it to a different size.
Some insights on data;
1) Variables of 4 D array are (Longitude, latitude, depth, time).
2) Size of the array is [176,239,5,248]. I have to change/interpolate the size of array to [112,152,5,248]. Can someone please help in making the above said change(s)?
This is link to data file.
Thanks in advance!
  댓글 수: 4
KALYAN ACHARJYA
KALYAN ACHARJYA 2023년 12월 5일
Please provide the array sizes [x,y,z,t]?
bhakti
bhakti 2023년 12월 5일
편집: bhakti 2023년 12월 5일
Hello Kalyan,
Thanks for your response.
Size of the array is [176,239,5,248] and it has to be changed/interpolated to [112,152,5,248].

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

채택된 답변

Torsten
Torsten 2023년 12월 6일
이동: Torsten 2023년 12월 6일
% Generate artificial data in longitude and latitude (176 points resp. 239
% points)
longdata = linspace(0,2,176);
latdata = linspace(0,5,239);
veldata = rand(numel(longdata),numel(latdata),5,248);
% Prescribe new grid in longitude and latitude direction (112 points resp.
% 152 points)
longdata_new = linspace(0,2,112);
latdata_new = linspace(0,5,152);
% Build new grid
[longq,latq] = meshgrid(longdata_new,latdata_new);
% Compute new velocity data
veldata_new = zeros(numel(longdata_new),numel(latdata_new),5,248);
for iz = 1:5
for it = 1:248
veldata_cut = veldata(:,:,iz,it);
veldata_new(:,:,iz,it) = interp2(longdata,latdata,veldata_cut.',longq,latq).';
end
end

추가 답변 (2개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 12월 5일
Your data size is [176 238 5 248] and not [176,239,40,248].
In this case, interpolate your multi-D data, griddatan() to be used: DOC
  댓글 수: 5
Torsten
Torsten 2023년 12월 6일
And you want to compute velocity on a new grid for Longitude and Latitude with depth and time unchanged ?
bhakti
bhakti 2023년 12월 6일
Hello Torsten,
Thanks for your response.
Yes, that's what I am looking for.

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


Matt J
Matt J 2023년 12월 5일
You can use imresizen, to be downloaded from
A= rand([176,239,5,248]);
B=imresizen(A, [112,152,5,248]./[176,239,5,248]);
whos A B
Name Size Bytes Class Attributes A 176x239x5x248 417274880 double B 112x152x5x248 168878080 double
  댓글 수: 3
Matt J
Matt J 2023년 12월 6일
I don't fully understand the question, but imresizen is doing interpolation, just as you requested.
bhakti
bhakti 2023년 12월 8일
Okay, I would try this.
Thank you.

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

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by