Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Find values in Matrix

Subject: Find values in Matrix

From: matthew mccarthy

Date: 23 Mar, 2009 01:04:01

Message: 1 of 6

I am having trouble finding values in two matrices. I have two matrices that are both 215x215 and I need to find two values in one matrix that are also in the other. The problem I am having is I can only find one value. I am trying to use the [r,c]=find(m=v).
Thanks for the help

Subject: Find values in Matrix

From: Vinod Karanth

Date: 23 Mar, 2009 01:43:02

Message: 2 of 6

"matthew mccarthy" <batter8@aol.com> wrote in message <gq6n61$di7$1@fred.mathworks.com>...
> I am having trouble finding values in two matrices. I have two matrices that are both 215x215 and I need to find two values in one matrix that are also in the other. The problem I am having is I can only find one value. I am trying to use the [r,c]=find(m=v).
> Thanks for the help

Matthew,

Try using this:
[r c]=find(m==v)

Cheers
VK

Subject: Find values in Matrix

From: Jonathan

Date: 23 Mar, 2009 01:45:03

Message: 3 of 6

"matthew mccarthy" <batter8@aol.com> wrote in message <gq6n61$di7$1@fred.mathworks.com>...
> I am having trouble finding values in two matrices. I have two matrices that are both 215x215 and I need to find two values in one matrix that are also in the other. The problem I am having is I can only find one value. I am trying to use the [r,c]=find(m=v).
> Thanks for the help

Be sure that the values that you are trying to find are in the same row/column in each matrix.

Also, it may be a typo but:

[r,c] = find(m==v)

-Jonathan

Subject: Find values in Matrix

From: Vinod Karanth

Date: 23 Mar, 2009 01:46:01

Message: 4 of 6

"matthew mccarthy" <batter8@aol.com> wrote in message <gq6n61$di7$1@fred.mathworks.com>...
> I am having trouble finding values in two matrices. I have two matrices that are both 215x215 and I need to find two values in one matrix that are also in the other. The problem I am having is I can only find one value. I am trying to use the [r,c]=find(m=v).
> Thanks for the help

Matthew,

Try doing this:
[r c]=find(m==v)

Cheers,
VK

Subject: Find values in Matrix

From: Matt Fig

Date: 23 Mar, 2009 02:17:01

Message: 5 of 6

"matthew mccarthy" <batter8@aol.com> wrote in message <gq6n61$di7$1@fred.mathworks.com>...
> I am having trouble finding values in two matrices. I have two matrices that are both 215x215 and I need to find two values in one matrix that are also in the other. The problem I am having is I can only find one value. I am trying to use the [r,c]=find(m=v).
> Thanks for the help

Note that beside the obvious typo, this may not be what you need. Try ismember.

Subject: Find values in Matrix

From: Roger Stafford

Date: 23 Mar, 2009 05:03:02

Message: 6 of 6

"matthew mccarthy" <batter8@aol.com> wrote in message <gq6n61$di7$1@fred.mathworks.com>...
> I am having trouble finding values in two matrices. I have two matrices that are both 215x215 and I need to find two values in one matrix that are also in the other. The problem I am having is I can only find one value. I am trying to use the [r,c]=find(m=v).
> Thanks for the help

  What precisely do you mean by "find two values in one matrix that are also in the other"? I would interpret this language as meaning that the locations of common elements in the two matrices do not have to be the same. In that case, the use of 'find' is inappropriate. It only finds elements that match both in value and in location.

  Instead you should use 'intersect'.

 c = intersect(a,b);

where a and b are the two matrices. The vector c will contain all elements common to both a and, regardless of location. If c contains more than two elements, the first two (or any two) would satisfy your requirements.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us