This answer originally came from the following link, although I didn't really understand it until I actually ran into an error in my code with the unexpected behavior.
The question is, given A and B are N-D matrices, what is the size of:
C = A(B);
From memory, I would say that the size of C is the size of B.
This is mostly true, EXCEPT if A and B are both vectors , then size of C is the size of A.
I ran into this problem with the following code:
best_number_dimensions = someFunction();
C = A(B(:,1:best_number_dimensions)); %A happened to be a row vector
D = mean(C,2);
Normally, D will have the same length as the first dimension of B. However, if for some reason ' best_number_dimensions ' equals 1, then A determines the size of C. Since I've said A is a row vector, C is now a row vector, which means that D is now a scalar, which was not what I intended.
A simple example of this would be the following:
A = 1:10;
B1 = [3; 4]; %column vector
C1 = A(B1); %row vector
B2 = [3 5; 4 6;]; %non-vector matrix
C2 = A(B2); %matrix the size of B2