Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Find entries (vector) within matrix

50 views
Skip to first unread message

John Laberga

unread,
Jun 10, 2009, 8:41:02 AM6/10/09
to
Hello,

I need concerning this small problem:
Let's say that I have a matrix:

A =
11 22 33
44 55 66
11 11 11
22 22 22
...
and so on, all rows are unique, size: 3xn

Now I want to check this matrix for specific row entry... let's say I want to know the location of the [11 11 11] "vector".

Is there a simple command for this or do I need to code the check myself?
Thanks!

John Laberga

unread,
Jun 10, 2009, 8:41:02 AM6/10/09
to

Matt Fig

unread,
Jun 10, 2009, 8:50:18 AM6/10/09
to
Check out ismember with the 'rows' option.

Tim Love

unread,
Jun 10, 2009, 8:59:27 AM6/10/09
to
> ...

>Now I want to check this matrix for specific row entry... let's say I want to know the location of the [11 11 11] "vector".

>Is there a simple command for this or do I need to code the check myself?

ismember(A, [11 11 11] ,'rows')

(which I agree isn't easy to guess, though your question is a common one)

Siyi

unread,
Jun 10, 2009, 4:50:57 PM6/10/09
to

to allow some tolerance (e.g. floating point error):

% engine;
locrow = @(A,x,tol)find(sum(abs(bsxfun(@minus,A,x)),2) <= tol)


% usage;
tol = 0.01
locrow(A,[11.0001, 11.0001, 10.9999], tol)

Eamonn

unread,
Jul 15, 2009, 7:46:02 AM7/15/09
to
"Matt Fig" <spam...@yahoo.com> wrote in message <h0oa6a$3t3$1...@fred.mathworks.com>...

> Check out ismember with the 'rows' option.

suppose there was a similar problem to above where the rows were not unique. Is there a way to count the occurances of a row from matrix X in matrix Y without a loop?

Thanks,

Eamonn

Bruno Luong

unread,
Jul 15, 2009, 8:02:01 AM7/15/09
to
"Eamonn " <eamonn...@gmail.com> wrote in message <h3kfhq$bui$1...@fred.mathworks.com>...

> "Matt Fig" <spam...@yahoo.com> wrote in message <h0oa6a$3t3$1...@fred.mathworks.com>...
> > Check out ismember with the 'rows' option.
>
> suppose there was a similar problem to above where the rows were not unique. Is there a way to count the occurances of a row from matrix X in matrix Y without a loop?
>

Check out the second output of ISMEMBER, then use FIND+SUM, or UNIQUE+HISTC or ACCUMARRAY or SPARSE, depending what exactly you want to do. If you want to set a floating point tolerance, use ISMEMBERF on FEX instead.

Bruno

0 new messages