[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: find
From: |
Rob Mahurin |
Subject: |
Re: find |
Date: |
Thu, 4 Jun 2009 16:08:46 -0400 |
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 address@hidden
- find, Carlo Rossi, 2009/06/04
- find, Carlo Rossi, 2009/06/04
- find, Carlo Rossi, 2009/06/04
- Re: find, Carlo Rossi, 2009/06/04
- Re: find, James Sherman Jr., 2009/06/04
- Re: find,
Rob Mahurin <=
- Re: find, Carlo Rossi, 2009/06/06