find intersection between matrix and vector

4 views (last 30 days)
I have a matrix and a vector:
M =
1.0e+010 *
0.1499 0.2998 0.4497 0.0996 0.2495
0.3501 0.2002 0.0503 0.4004 0.2505
0.6499 0.7998 0.9497 0.5996 0.7495
0.8501 0.7002 0.5503 0.9004 0.7505
1.1499 1.2998 1.4497 1.0996 1.2495
1.3501 1.2002 1.0503 1.4004 1.2505
1.6499 1.7998 1.9497 1.5996 1.7495
1.8501 1.7002 1.5503 1.9004 1.7505
v =
1.0e+009 *
1.499 2.998 4.497 5.996 7.495
How can I find the index locations in M where its value == anyone in vector v? Is there a function for this or do I have to use a FOR loop? FIND() only works on vectors.

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 23 Sep 2011
help ismember
You need to be careful about the floating point comparison though.
M=magic(10);
V=1:10;
[TF,LOC]=ismember(M,V)
  1 Comment
Jan
Jan on 23 Sep 2011
And if you run into floating point problems: http://www.mathworks.com/matlabcentral/fileexchange/23294-ismemberf

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 23 Sep 2011
You probably will not be able to do that using ismember(). See http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!