find intersection between matrix and vector

2 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by