How to to report row at which the difference reaches below a threshold?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Miraculous Mongoose
am 9 Sep. 2019
Kommentiert: the cyclist
am 9 Sep. 2019
For example, if I have this matrix, transposed:
a = [10 7 5 2 1 0.5 0.4 0.3 0.3 ...]
i.e. it is getting smaller at a decreasing rate.
And I want to report the row in which the difference gets sufficiently small, or almost at steady state. I would want it to report the row of 0.4 or the 1st 0.3.
How can I do this?
0 Kommentare
Akzeptierte Antwort
the cyclist
am 9 Sep. 2019
Bearbeitet: the cyclist
am 9 Sep. 2019
Probably the hardest part will be defining the exact rule for "sufficiently small difference". After that, I think something like
threshold = 0.11;
find(diff(-a) < threshold,1);
will find what you want. Note that diff(a) is one element shorter than a, so be careful with indexing.
Also, it is a bit trickier if you need to define a relatively small difference (compared to earlier differences), rather than an absolute difference (as I did here with 0.11 threshold).
1 Kommentar
the cyclist
am 9 Sep. 2019
Oh, another cautionary note: Be wary of checking an exact threshold value. Because some decimal numbers cannot be represented exactly, you need to be careful of floating point error in calculations like
>> (0.5-0.4)-0.1
ans =
-2.775557561562891e-17
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!