I'm looking to eliminate the following for loop:
Mostrar comentarios más antiguos
I'm looking to eliminate the following for loop:
for j=1:96
rn(ijk(j))=rn(ijk(j))+mp(j);
end
Background: rn is a 200x3x3 matrix, ijk is a 1800x1 matrix and np is a 12x8 matrix. ijk describes the mapping between mp and (the much larger) rn. For example, when j=1, mp(j)=0.84 and ijk(1)=601. This loop is embedded in a much larger loop.
There has got to be a way to eliminate the for loop presented here. Any suggestions?
Respuesta aceptada
Más respuestas (2)
Sean de Wolski
el 18 de En. de 2012
%Data:
mp=[0.1;0.2;0.3];
ijk=[1,2,1];
rnsz = [4 1]; %the size you want rn to be:
%Engine:
rn = accumarray(ijk',mp',rnsz); % Build rn; note transpose of subs/vals
1 comentario
John
el 18 de En. de 2012
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!