I have a vector a
and a second vector b
to access a range of indices in a
, all working as I would expect:
a=1:5400; % a==[1 2 3 4 ...] value: (1x5400 double)
b=[1 2 3]; % b value: (1x3 double)
a(b); % returns [1 2 3]
however if a b
is a 2D matrix and a
is matched to the size of b
:
a=1:5400;
b=[1 2 3; 4 5 6; 7 8 9];
a=repmat(a,3,1); %expand matrix to match dimensions of b
c=a(b);
I get an unexpected result: c == [1 1 1;2 2 2;3 3 3]
when I expected [1 2 3;4 5 6;7 8 9]
Can somebody offer an explanation?