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

97 次查看(过去 30 天)
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).

回答(1 个)

Walter Roberson
Walter Roberson 2016-12-20
编辑:Walter Roberson 2016-12-20
find(y >= 0.98, 1, 'last')
Or for your expanded requirement,
find(y >= 0.98 & y <= 1.02, 1, 'last')
  3 个评论
Walter Roberson
Walter Roberson 2016-12-20
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 2023-9-21
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');

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by