Interpolating [3,3] matrix valued function using interp3

조회 수: 1 (최근 30일)
memductance
memductance 2021년 10월 29일
답변: Rishabh Singh 2021년 11월 5일
Hello everyone
I have a [3,3] matrix valued function that I would like to interpolate using interp3 if that is possible. The sampled function is given in the form of a [N,N,N,3,3] matrix similar to the code sample below:
N=25;
coords=linspace(0,1,N);
[X,Y,Z]=meshgrid(coords,coords,coords);
values=zeros(N,N,N,3,3);
for i=1:1:N
for j=1:1:N
for k=1:1:N
values(i,j,k,:,:)=rand(3,3);
end
end
end
f=@(x,y,z) interp3(X,Y,Z,values,x,y,z);
f(0.5,0.5,0.5)
I'm not quite sure how I should go about using interp3 to interpolate said function?

답변 (1개)

Rishabh Singh
Rishabh Singh 2021년 11월 5일
Since your matrix is 5-Dimensional you will have to use "interpn", and "ndgrid".
Below code should work, and provide you the required output.
N=25;
coords=linspace(0,1,N);
[X,Y,Z]=ndgrid(coords,coords,coords);
values=zeros(N,N,N,3,3);
for i=1:1:N
for j=1:1:N
for k=1:1:
values(i,j,k,:,:) = rand(3,3);
end
end
end
f=@(x,y,z) interpn(X,Y,Z,values,x,y,z);
output = squeeze(f(0.5,0.5,0.5))
Hope this helps.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by