Linearly increasing groups of indices
Mostrar comentarios más antiguos
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!
1 comentario
Nils
el 12 de Mzo. de 2013
Respuesta aceptada
Más respuestas (2)
Sean de Wolski
el 11 de Mzo. de 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
el 12 de Mzo. de 2013
out = bsxfun(@plus,[1;3;4],0:10:10*(floor(x(end)/10)-1));
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!