3D interpolation using Griddata

43 次查看(过去 30 天)
I have a 3D gridded data. The 3D grid is partitioned as:
a = [0.25, 0.5, 0.75];
b = [0.25, 0.5, 0.75];
c = [1,2,3];
[A,B,C] = meshgrid(a,b,c);
We have data at each grid point. The data is given by:
Arr = [1 2 3; 4 5 6; 7 8 9] ;
Arr(:,:,2) = [10 11 12; 13 14 15; 16 17 18];
Arr(:,:,3) = [15 16 17; 18 19 20; 21 22 23];
I would like to interpolate the data(Arr) along the C axis, at 2.5.. Please, how can I do that?

采纳的回答

Rahul
Rahul 2023-6-23
According to the information shared, you currently have 3D gridded data and data at each grid point. You are further trying to interpolate the data at each point along the z-axis with a value of 2.5. This can be done by using interp3 function in the following way.
% Given data
a = [0.25, 0.5, 0.75];
b = [0.25, 0.5, 0.75];
c = [1, 2, 3];
[A, B, C] = meshgrid(a, b, c);
Arr = [1 2 3; 4 5 6;7 8 9];
Arr(:, :, 2) = [10 11 12; 13 14 15;16 17 18];
Arr(:, :, 3) = [15 16 17; 18 19 20; 21 22 23];
% Interpolate along the C axis at 2.5
interp_value = 2.5;
Now you need to query coordinates matching the size of A, B, and C in the following way.
[Xq, Yq, Zq] = meshgrid(a, b, interp_value);
Now after obtaining the meshgrid along different axis and query coordinates with the new interpolated mesh grid information, we can interpolate the available data at each grid point using interp3 function like,
interpolated_result = interp3(A, B, C, Arr, Xq, Yq, Zq);
disp(interpolated_result);
You can find more information about interp3 function from below given resources. Thanks.
  1 个评论
Telema Harry
Telema Harry 2023-6-23
编辑:Telema Harry 2023-6-23
Thank you @Rahul.
I will like to create a new Array by insertng the interpolated_result in Arr.
One way to to that is probably slicing each z-axis and concatenating all of them with.
Arr1 = Arr(:, :, 1);
Arr2 = Arr(:, :, 2);
Arr3 = Arr(:, :, 3);
New_array = cat( 3,Arr1,Arr2,interpolated_result,Arr3 );
I have a large dataset, and it will be a pain doing it manually. Please, is there an easier way to form a new 3D array?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by