필터 지우기
필터 지우기

Find an element of a matrix equal to a constant

조회 수: 20 (최근 30일)
cyberdyne
cyberdyne 2011년 3월 29일
Hi,
If B is a matrix i need to find the index of element that is equal to a constant c where the constant c is undoubtedly somewhere in the matrix.
I tried to do:
B(:,B(2,:)==c)
but there are some problems with logical operator ==
It returns me "Empty matrix"

답변 (1개)

Matt Fig
Matt Fig 2011년 3월 29일
If you are looking for the linear index:
I = find(B==c);
If you are looking for the subscript index:
[I,J] = find(B==c);
I hope you are not experiencing a floating point issue???
Whenever I hear somebody say they cannot find a value that they just know is in an array, I wonder if they are not about to learn the joys of floating point arithmetic.
  댓글 수: 3
Walter Roberson
Walter Roberson 2011년 3월 29일
Yup, see the link Matt posted about floating point issues.
cyberdyne
cyberdyne 2011년 3월 29일
Great! The problem was it. Thanks.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by