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!