3D interpolation using Griddata

29 views (last 30 days)
Telema Harry
Telema Harry on 23 Jun 2023
Edited: Telema Harry on 23 Jun 2023
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?

Accepted Answer

Rahul
Rahul on 23 Jun 2023
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 Comment
Telema Harry
Telema Harry on 23 Jun 2023
Edited: Telema Harry on 23 Jun 2023
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?

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!