How to to report row at which the difference reaches below a threshold?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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
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 Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!