i have 1x10 vector a
a = [11 22 33 44 55 66 77 88 99 111]
each value in a
represents index in vector b
1x200.
i want each value in vector a
, go index of value in vector b
, value of index , 10 items before , 10 items after.
for example, first element in vector a
11, i'll go index 11 in vector b
, value of index (11th value) , value of 10 items before (from 1 10) , 10 items after (from 12 21), same every element in a
.
is possible without loops?
here on using bsxfun
r = b(bsxfun(@plus, a(:), -10:10));
now row n
in r
contains elements corresponding element n
in a
. if want in vector use:
r = reshape(b(bsxfun(@plus, a(:), -10:10)), 1, []);