Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Get line index on matrix
Date: Thu, 5 Nov 2009 12:19:02 +0000 (UTC)
Organization: Erasmus MC
Lines: 49
Message-ID: <hcufrm$r7t$1@fred.mathworks.com>
References: <hcudtq$phk$1@fred.mathworks.com> <hcuetm$6t$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257423542 27901 172.30.248.37 (5 Nov 2009 12:19:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 5 Nov 2009 12:19:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 870065
Xref: news.mathworks.com comp.soft-sys.matlab:582692


"Wayne King" <wmkingty@gmail.com> wrote in message <hcuetm$6t$1@fred.mathworks.com>...
> "Joe Nunes" <vazdepaivanunes@gmail.com> wrote in message <hcudtq$phk$1@fred.mathworks.com>...
> > Hello,
> > 
> > I'm trying to get the line index of a nx3 matrix for a given vector (1x3), like
> > 
> > 0.1  0.3  1.6
> > 0.2  0.7  1.2
> > 1.3  0.1  7.3
> > (...)
> > 
> > searching for vector = 0.2 0.7 1.2 should return index = 2.
> > 
> > i've tried find() and a script which compares
> > 
> >     if(vector(i,:) == points(i,:))
> >         index = i;
> > 
> > inside a for() loop (but it says that the condition is not valid, on debug)
> > 
> > I would appreciate your help.
> > 
> > Best regards
> 
> Hi Joe, will the following work for you?
> 
> A=[0.1 0.3 1.6
> 0.2 0.7 1.2
> 1.3 0.1 7.3];
> B= [0.2 0.7 1.2];
> [C,IA] = intersect(A,B,'rows');
> % IA is equal to 2
> IA
> 
> Wayne

or take a look at ISMEMBER or even more directly BSXFUN (in combination with ALL)

A=[0.1 0.3 1.6 ; 0.2 0.7 1.2 ; 1.3 0.1 7.3]; B= [0.2 0.7 1.2];
t1 = bsxfun(@eq,A,B)
t2 = all(t1,2)
r = find(t2)

By the way, be quite careful when comparing floating points:

a = 0.1+0.2+0.3, b = 0.6, a==b

hth
Jos