Suppose you want to select A(1:2,2:3)
:
% Row and column indexes
rind = 1:2;
cind = 2:3;
pos = bsxfun(@plus,rind', size(A,2)*(cind-1));
pos =
6 11
7 12
You might want to reshape it into a column vector pos(:)
, or in one line with a call to reshape()
.