How can I vectorize this simple for loop?
Mostrar comentarios más antiguos
Given a 3D array:
a = rand(10, 10, 10);
and an integer index array:
idx = ceil(10 * rand(3, 1000));
is there a way (a clever indexing trick?) to vectorize the following loop:
b = zeros(1, 1000);
for i = 1:1000
b(i) = a(idx(1, i), idx(2, i), idx(3, i));
end
Thanks!
Respuesta aceptada
Más respuestas (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!