Let i
be your indicesx and x
the number of elements you want in addition to the elements in i
, then you can use
i = [4 6 8];
x = 4;
bsxfun(@plus, 0:x, i(:))
to get a matrix of indices:
ans =
4 5 6 7 8
6 7 8 9 10
8 9 10 11 12
If you do not have access to bsxfun
you can use repmat
instead:
i = [4 6 8];
x = 4;
repmat(i(:), 1, x+1) + repmat(0:x, length(i), 1)