Linearly increasing groups of indices
Show older comments
Hello, I think I can explain my question most easily with an example. If I only want to access every 10th element in an array a, then I can easily do this by a(1:10:end). But let's say that I am instead looking for groups of entries whose indices all are increasing with 10 all the way to the final index. For instance, access the entries with indices 1,3,4,11,13,14,21,23,24... Naturally a([1 3 4]:10:end) does not accomplish this. Is there a way that I through indexing could do this without a loop?
Thanks in advance!
Accepted Answer
More Answers (2)
Sean de Wolski
on 11 Mar 2013
A = 1:100;
A(sort([1:10:end, 3:10:end,4:10:end])) = pi
Of course a for-loop might be faster.
Andrei Bobrov
on 12 Mar 2013
out = bsxfun(@plus,[1;3;4],0:10:10*(floor(x(end)/10)-1));
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!