Simple Question about Optimization of a FOR loop
Mostrar comentarios más antiguos
How can I optimize (vectorize?) the following code in order to avoid the for loop and make the code to run faster?
for i=1:55;
A(i)=B((i-1)*3+1,1);
end
A is 1 x 55 and B is 165 x 1
Many thanks!
3 comentarios
Matt Kindig
el 14 de Jun. de 2013
This loop will make A only 1x55, not 55x55.
Laila Kazemi
el 14 de Jun. de 2013
bc ur only assigning one raw to A
Mohsen
el 14 de Jun. de 2013
Respuestas (2)
Laila Kazemi
el 14 de Jun. de 2013
0 votos
C= B*3 +1 A (1:55, 1:55)= C(1:55, 1)
but the dimensions of ur matrices dont match , if B was 55 by 1 , it would have worked
3 comentarios
Laila Kazemi
el 14 de Jun. de 2013
C= B*3 +1
A (1:55, 1:55)= C(1:55, 1)
Laila Kazemi
el 14 de Jun. de 2013
actaully instead one make a matrix called D with D( , 1:165)=(1)
Mohsen
el 16 de Jun. de 2013
Andrei Bobrov
el 14 de Jun. de 2013
A(1,:) = B((0:size(A,2)-1)*3+1);
1 comentario
Mohsen
el 16 de Jun. de 2013
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!