matlab question

Given  a matrix A, say

0    0    20
0    5    10
4    9     4
0    0      0

and a vector

a =[0 0 0 0]

How to determine a is 4-th row in A?

A quick matlab code looks like

find(ismember(A,a,’rows’))

Here is another solution which is harder to understand

e = A-repmat(a, [size(A, 1), 1]);
i = find(sum(e==0, 2)==size(A, 2));

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.