[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How do I replace this "for" loop?
From: |
Tom Holroyd |
Subject: |
Re: How do I replace this "for" loop? |
Date: |
Tue, 31 May 2005 21:15:56 -0400 (EDT) |
Oops! There was a(nother) bug in my script -- the original line
was
x = 2*(x>p);
but it should have been
x = 2*x(x>p);
and the really astonishing part is, the second line is faster.
In fact (see attached graph), it shows that in this case, find is
*never* faster than using logical indexing. Not only that, even
the logical indexing gets faster as the number of elements
selected decreases! I'm not sure why that is.
The first line involves conversion of a logical array to a double
array, which has nothing to do with the original task.
Dr. Tom Holroyd
"A man of genius makes no mistakes. His errors are volitional and
are the portals of discovery." -- James Joyce
trade2.png
Description: PNG image