|
"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.
|