I have a 3D matrix defined like so:
A = zeros(3,3,3)*3;
A(:,:,1) = [1 2 3; 3 2 1; 3 4 7];
A(:,:,2) = [4 5 6; 6 5 4; 2 5 8];
A(:,:,3) = [7 8 9; 9 8 7; 3 6 9];
My goal is to extract a 2D matrix by interpolating 2 consecutive layers of the 3D matrix. In this example i want the matrix at a 75% distance between layer 1 and 2. I was able to achieve this by doing a simple linear interpolation but I would like to get some better and smarter way to perform this task maybe taking advantage of the built-in Matlab functions.
l = 1; % Layer: 1<= l <= size(A,3)-1
x = 0.75; % Distance at which i want to interpolate from layer 0<= x <= 1
AMin = A(:,:,l);
AMax = A(:,:,l+1);
AMin + (AMax-AMin)*x
Which returns
3.25 4.25 5.25
5.25 4.25 3.25
2.25 4.75 7.75
as expected.