How to to report row at which the difference reaches below a threshold?

1 回表示 (過去 30 日間)
Miraculous Mongoose
Miraculous Mongoose 2019 年 9 月 9 日
コメント済み: the cyclist 2019 年 9 月 9 日
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?

採用された回答

the cyclist
the cyclist 2019 年 9 月 9 日
編集済み: the cyclist 2019 年 9 月 9 日
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 件のコメント
the cyclist
the cyclist 2019 年 9 月 9 日
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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by