Filter löschen
Filter löschen

find a values in matrix

1 Ansicht (letzte 30 Tage)
Tomas
Tomas am 23 Nov. 2013
Bearbeitet: dpb am 24 Nov. 2013
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

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 23 Nov. 2013
Maybe you are looking for the location
H=[ 0 2.3926
2.3926 0]
[ii,jj]=find(H==2.3926)

Weitere Antworten (1)

dpb
dpb am 23 Nov. 2013
Bearbeitet: dpb am 23 Nov. 2013
val=2.3926;
A=H(abs(H-val)<1.e-5);
NB the "fuzzy" comparison to avoid FP precision problems
  2 Kommentare
Tomas
Tomas am 23 Nov. 2013
Bearbeitet: Tomas am 23 Nov. 2013
little easier ?
will it work on different numbers in the matrix?
dpb
dpb am 23 Nov. 2013
Bearbeitet: dpb am 24 Nov. 2013
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Fuzzy Logic Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by