find

Rob Mahurin rob at utk.edu
Thu Jun 4 15:08:46 CDT 2009


On Jun 4, 2009, at 11:26 AM, Carlo Rossi wrote:
> Hello,
>
> class = [1  1 1 -1 -1 1];
>
> This is is what I need:
>
> idx1 = find(class == 1); %retrieve the indexes of '1': 1,2,3,6
> idx2 = find(class == -1); % retrieve 4,5
>
> But I'd like to know if it's possible write it in a hit (and I need  
> 2 different variables, id2, idx2)

The expression (class == 1) returns a vector of logical values, in  
your case [ 1 1 1 0 0 1 ].  You can use this as a mask in the same  
way you use your idx1, i.e.

idx = (class == 1);
class(idx), # this displays all ones
class(!idx), # this doesn't display any ones

I think this is cleaner than using two calls to find, but I don't  
know what you're trying to do, either.

Rob

-- 
Rob Mahurin
Department of Physics and Astronomy
University of Tennessee 		865 207 2594
Knoxville, TN 37996 			rob at utk.edu





More information about the Help-octave mailing list