[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
vectorization
From: |
David Pruitt |
Subject: |
vectorization |
Date: |
Tue, 3 Dec 2002 13:51:14 -0600 |
In some work I'm now doing, I continually find the need to determine the
set of indices of vector A which contain elements of vector B - elements of
B will occur in A no more than once. Here's an example of what my code
looks like:
# contrived example
# vector A
i_num = [1:100];
# vector B
v_num = [ 1 3 5 12 ];
lt = length(v_num);
for i = 1:lt
idx(i) = find( i_num == v_num(i) );
endfor;
In this example, idx would of course be 1,3,5,12. So it's sort of a
two-dimensional "find". I'll just bet I'm doing this the hard way. Is
there another way without a for-loop? For the cases I'm seriously
concerned with, the vectors contain 5,000 to 15,000 elements.
Thanks,
David
-------------------------------------------------------------
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
-------------------------------------------------------------
- vectorization,
David Pruitt <=