Linearly increasing groups of indices
이전 댓글 표시
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!
채택된 답변
추가 답변 (2개)
Sean de Wolski
2013년 3월 11일
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
2013년 3월 12일
out = bsxfun(@plus,[1;3;4],0:10:10*(floor(x(end)/10)-1));
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!