help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I replace this "for" loop?


From: Keith Goodman
Subject: Re: How do I replace this "for" loop?
Date: Tue, 31 May 2005 14:39:48 -0700

How much time does the extra find step add?

>> N = 1000; x = rand(N); tic; x = 2*(x>0);toc
ans = 0.029154
>> N = 1000; x = rand(N); tic; x = 2*(x>0);toc
ans = 0.028811
>> N = 1000; x = rand(N); tic; x = 2*(x>0);toc
ans = 0.028760

>> N = 1000; x = rand(N); tic; idx = find(x>0);x(idx) = 2*x(idx);toc
ans = 0.59328
>> N = 1000; x = rand(N); tic; idx = find(x>0);x(idx) = 2*x(idx);toc
ans = 0.59345
>> N = 1000; x = rand(N); tic; idx = find(x>0);x(idx) = 2*x(idx);toc
ans = 0.59398

If your matrix is big, avoid the find step.



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]