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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by