|
From: | Carlo de Falco |
Subject: | Re: help requested with extremely slow for loop? |
Date: | Wed, 24 Mar 2010 14:36:05 +0100 |
On 24 Mar 2010, at 11:22, Joachim De Beule wrote:
octave> idxs = find(x & y); octace> tic for j = idxs x(y(j)) += x(j); x(j) = 0; endfor toc octave> Elapsed time is 15.96 seconds.Does anybody have an idea what is going on here or have suggestions about how to do this differently? Basically, y(j) holds the new j' that should get thevalue of x(j), after which x(j) itself needs to be set to zero...
what about the following? idxs = find (x & y); x(y(idxs)) += x(idxs); x(idxs)=0; I haven't actually tested it but it should do the same as your code... you might also want to try: idxs = (x & y); x(y(idxs)) += x(idxs); x(idxs)=0;
Thanks! Joachim.
HTH, c.
[Prev in Thread] | Current Thread | [Next in Thread] |