find intersection between matrix and vector

2 ビュー (過去 30 日間)
Leor Greenberger
Leor Greenberger 2011 年 9 月 23 日
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.

採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 9 月 23 日
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 件のコメント
Jan
Jan 2011 年 9 月 23 日
And if you run into floating point problems: http://www.mathworks.com/matlabcentral/fileexchange/23294-ismemberf

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 9 月 23 日
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

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by