3D interpolation using interp1

조회 수: 9 (최근 30일)
Emma Smolders . 2021년 11월 12일
댓글: Emma Smolders . 2021년 11월 12일
Dear all,
I have a velocity field in a lake whichis contructed on a (m,n,k) grid where m is the number of grid points in the x-direction, n in the y-direction and k the number of vertical layers. At the moment, I have 100 layers (so k = 100) distributed over a depth of 350 meters. I would like to interpolate this velocity field to 200 layers in the vertical distributed over the same depth. I thought the following piece of code would work, where z1 is a (1,100) array containing depth layers and z2 a (1,200) array containing 200 depth layers on which I would like the velocity field to be interpolated. This code does not work since I get the error that X and V must be of the same length. But they are of the same length, right? Does anyone know how to code this properly?
for i = 1:m
for j = 1:n
interp_u = interp1(z1, u(i, j, :), z2, 'linear')
end
end

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

채택된 답변

Matt J 2021년 11월 12일
편집: Matt J 님. 2021년 11월 12일
F=griddedInterpolant({1:m,1:n,z1},u);
interp_u=F({1:m,1:n,z2});
댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Emma Smolders 2021년 11월 12일
Thanks! I think this is working :)

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

카테고리

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

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by