Path: news.mathworks.com!not-for-mail
From: "gozer " <wolfeb@timken.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Stumped on a Matrix Analysis
Date: Thu, 26 Nov 2009 01:22:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 23
Message-ID: <hekl7t$q79$1@fred.mathworks.com>
References: <hej6uj$hqq$1@fred.mathworks.com> <hej9hi$qko$1@fred.mathworks.com>
Reply-To: "gozer " <wolfeb@timken.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1259198525 26857 172.30.248.35 (26 Nov 2009 01:22:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 26 Nov 2009 01:22:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2109650
Xref: news.mathworks.com comp.soft-sys.matlab:587966


"Jos (10584) " <#10584@fileexchange.com> wrote in message <hej9hi$qko$1@fred.mathworks.com>...
> "gozer " <wolfeb@timken.com> wrote in message <hej6uj$hqq$1@fred.mathworks.com>...
> > I am a novice and stumped with what may be a simple problem but not sure how to attack.  I have a matrix A=m x n and a smaller matrix filterA=[2:6,21,34,35:43].  I would like to return a matrix B that contains all rows of A whose value in col 'n'  matches a value in filterA.
> > I have looked at 'filter', 'sort', sortrows, 'ismember' and others but none seem to be the right thing.  Even tried multiple if-thens but that got messy quickly.
> 
> From your description I think your after this (a small example might have help here!)
> 
> % data
>   A = [ 1 2 3 ; 2 3 4 ; 1 3 4 ; 2 1 5 ; 2 4 3 ; 3 1 3] ; % arbitrary m-by-n array
>   filterA = [3 4] ;
> 
> % task: keep only those rows in A for which the last element is present in "filterA"
> % engine (can be written in a one-liner)
>   Col_n_of_A = A(:,end) ; % n-th, i.e. last column of A
>   tf = ismember(Col_n_of_A, filterA) ; 
>   B = A(tf,:) 
> 
> hth
> Jos

Jos,
You nailed it dead on.  Code does exactly what I was looking for.  You saved me a bunch of stress.....owe  you one!
thanks.