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

89 visualizzazioni (ultimi 30 giorni)
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).

Risposte (1)

Walter Roberson
Walter Roberson il 20 Dic 2016
Modificato: Walter Roberson il 20 Dic 2016
find(y >= 0.98, 1, 'last')
Or for your expanded requirement,
find(y >= 0.98 & y <= 1.02, 1, 'last')
  3 Commenti
Walter Roberson
Walter Roberson il 20 Dic 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 il 21 Set 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');

Accedi per commentare.

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by