필터 지우기
필터 지우기

3D interpolation using Griddata

조회 수: 23 (최근 30일)
Telema Harry
Telema Harry 2023년 6월 23일
편집: Telema Harry 2023년 6월 23일
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