Speeding up a loop
Mostrar comentarios más antiguos
I have made a simple loop that works fine when dealing with small datasets, but takes ages to run when L is 10^6 in size - which unfortunately is the size I need to work with. I'm sure you can tell by the code itself I'm a matlab newbie, so any ideas on how this can be sped up would be very much appreciated. I've read about vectorisation but cannot work out how to vectorise this code.
C=cumsum(S);
L=length(C);
X=zeros(1,L)';
for i=1:L;
if C(i)>min(C(i:L));
X(i);
else
X(i)=1;
end
end
4 comentarios
Rick Rosson
el 17 de En. de 2013
Editada: Rick Rosson
el 17 de En. de 2013
Is S a row vector or a column vector?
Rick Rosson
el 17 de En. de 2013
Editada: Rick Rosson
el 17 de En. de 2013
What is the goal of this algorithm? What do the variables S and X represent?
Jan
el 17 de En. de 2013
Is the wanted property of C directly related to the sign of the corresponding element of S?
Respuesta aceptada
Más respuestas (1)
Swisslog
el 17 de En. de 2013
0 votos
Categorías
Más información sobre Loops and Conditional Statements 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!