How to index the matrix only the first dimension of the rest
10 views (last 30 days)
Stephen23 on 1 Sep 2022
This will be quite efficient because none of the data in memory is moved around, only the array header is accessed.
It also works for non-scalar X.
B = A(X,:);
S = size(A);
S(1) = size(B,1);
B = reshape(B,S);
Walter Roberson on 31 Aug 2022
However this will treat it like
temp = reshape(A, size(A, 1), );
B = temp(1,:);
which would give you a 1 x 12 not a 1 x 4 x 3