find a values in matrix

조회 수: 6 (최근 30일)
Tomas
Tomas 2013년 11월 23일
편집: dpb 2013년 11월 24일
I have matrix H[ 0 2.3926
2.3926 0]
I want to find value in matrix H, 2.3926 and store it in a variable A

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 11월 23일
Maybe you are looking for the location
H=[ 0 2.3926
2.3926 0]
[ii,jj]=find(H==2.3926)

추가 답변 (1개)

dpb
dpb 2013년 11월 23일
편집: dpb 2013년 11월 23일
val=2.3926;
A=H(abs(H-val)<1.e-5);
NB the "fuzzy" comparison to avoid FP precision problems
  댓글 수: 2
Tomas
Tomas 2013년 11월 23일
편집: Tomas 2013년 11월 23일
little easier ?
will it work on different numbers in the matrix?
dpb
dpb 2013년 11월 23일
편집: dpb 2013년 11월 24일
Not sure what the question is, precisely. Of course the comparison can be any value or range of values. There are times when owing to FP rounding find(x==val) won't return what is naively expected.
You can always write
A=H(H==2.3926);
and for some cases you'll find joy, in others "not so much"
Look up "logical addressing" in the documentation for more detail of how this works.

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

카테고리

Help CenterFile Exchange에서 Fuzzy Logic in Simulink에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by