Interpolating [3,3] matrix valued function using interp3

2 visualizzazioni (ultimi 30 giorni)
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?

Risposte (1)

Rishabh Singh
Rishabh Singh il 5 Nov 2021
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.

Categorie

Scopri di più su Interpolation in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by