Re: Matrix indexing: bug or wanted?



RobR:
<SNIP matrix indexing conundrum...

matrixIndex =
4 4 4 4 4
5 5 5 5 5
Xindexed =
8 8 8 8 8
9 9 9 9 9
dont't you think, Xindexed should be more like
Xindexed =
8 16 24 32 40
9 18 27 36 45

no, the first result is exactly right: it has been correct for 20+
years and will stay for years to come... more important, however, it
is really what you would expect it to be

one of the solutions for your request

% assume your X
x=X;
% the engine
[xr,xc]=size(x);
[ixr,ixc]=meshgrid((0:xc-1).*xr,4:5);
r=x(ixr+ixc);
% the result
r

-and- look at
help sub2ind
for more options

us
.