How to find the last position in an array where a value is met

96 visualizaciones (últimos 30 días)
Robert Marasescu
Robert Marasescu el 20 de Dic. de 2016
Comentada: Tanner DeKruyter el 21 de Sept. de 2023
I have an array of about 100 elements, all random generated by a function and I need to find the last position where the value 0.98 is met. Also, the values are with more than 6 decimals so they need to be approximated to just 2, but I can do that with round function.
Ox axis is an array that contains time values, and Oy axis is an array which contains the values of the function. I have to find the last value on Oy where y (the function) is + or - 2% of 1 (which is 0.98 or 1.02).

Respuestas (1)

Walter Roberson
Walter Roberson el 20 de Dic. de 2016
Editada: Walter Roberson el 20 de Dic. de 2016
find(y >= 0.98, 1, 'last')
Or for your expanded requirement,
find(y >= 0.98 & y <= 1.02, 1, 'last')
  3 comentarios
Walter Roberson
Walter Roberson el 20 de Dic. de 2016
What is the value of y(end) ? If the plot you included represents the data, then the value at the right hand side is between 0.98 and 1.02: visually we can see that the value is quite close to 1.0
Tanner DeKruyter
Tanner DeKruyter el 21 de Sept. de 2023
I know this is a bit late, but I'm in controls right now and just did this. You need to reverse the bounds to search outside the 2% from steady state. My code was instead:
ts_idx = find(or(y1 <= 0.98*yss, y1 >= 1.02*yss), 1, 'last');

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by