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

1 visualización (últimos 30 días)
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?

Respuesta aceptada

the cyclist
the cyclist el 9 de Sept. de 2019
Editada: the cyclist el 9 de Sept. de 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 comentario
the cyclist
the cyclist el 9 de Sept. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by