# Interpolating [3,3] matrix valued function using interp3

1 ビュー (過去 30 日間)
memductance 2021 年 10 月 29 日

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 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.

サインインしてコメントする。

### カテゴリ

Find more on Interpolation in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!