find intersection between matrix and vector

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.

 Risposta accettata

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 Commento

And if you run into floating point problems: http://www.mathworks.com/matlabcentral/fileexchange/23294-ismemberf

Accedi per commentare.

Categorie

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by