Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to take common rows and columns from two matrices.
Date: Mon, 13 Jun 2011 20:33:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 34
Message-ID: <it5s5u$iuq$1@newscl01ah.mathworks.com>
References: <ist0dv$our$1@newscl01ah.mathworks.com> <isunlg$t1k$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-00-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1307997182 19418 172.30.248.45 (13 Jun 2011 20:33:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 13 Jun 2011 20:33:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2910700
Xref: news.mathworks.com comp.soft-sys.matlab:731746

"Roger Stafford" wrote in message <isunlg$t1k$1@newscl01ah.mathworks.com>...
> "jewi" wrote in message <ist0dv$our$1@newscl01ah.mathworks.com>...
> > Hello all,
> > 
> > Could anyone help plz;
> > I have two matrices with different number of columns and rows.
> > e.g, 
> >      A =
> >      1     6    11    16
> >      2     7    12    17
> >      3     8    13    18
> >      4     9    14    19
> >      5    10    15    20
> > and
> >      B=
> >       2     7
> >       5     10
> > 
> > I want to select rows from A which are common with B, but i want to take the whole row from A with all columns.
> > For example in the above case my desired result would be;
> >    C=
> >    2 7 12 17
> >    5 10 15 20
> > 
> > Thanks,
> > Jewi.
> - - - - - - -
>   You can use the 'ismember' function with the 'rows' option to solve this problem in one line:
> 
>  C = A(ismember(A(:,1:size(B,2)),B,'rows'),:);
> 
> Roger Stafford

wow, its awesome. I love it. Just one line and worked perfectly. Thank you very much Roger.