Borrar filtros
Borrar filtros

Interpolating [3,3] matrix valued function using interp3

3 visualizaciones (últimos 30 días)
memductance
memductance el 29 de Oct. de 2021
Respondida: Rishabh Singh el 5 de Nov. de 2021
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?

Respuestas (1)

Rishabh Singh
Rishabh Singh el 5 de Nov. de 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.

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by