How to interpolate 2 dimensions of a 4D array ?
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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
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
2023-12-6
And you want to compute velocity on a new grid for Longitude and Latitude with depth and time unchanged ?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!