I have a 3d matrix H(i,j,k)
with dimensions (i=1:m,j=1:n,k=1:o)
. I will use a simple case with m=n=o = 2
:
H(:,:,1) =[1 2; 3 4];
H(:,:,2) =[5 6; 7 8];
I want to filter this matrix and project it to an (m,n)
matrix by selecting for each j in 1:n
a different k in 1:0
.
For instance, I would like to retrieve (j,k) = {(1,2), (2,1)}
, resulting in matrix G:
G = [5 2; 7 4];
This can be achieved with a for
loop:
filter = [2 1]; % meaning filter (j,k) = {(1,2), (2,1)}
for i = 1:length(filter)
G(:,i) = squeeze(H(:,i,filter(i)));
end
But I'm wondering if it is possible to avoid the for
loop via some smart indexing.