How to get the first value in a set of array that is bigger than the first few values?
1 view (last 30 days)
Wolfgang McCormack on 21 Feb 2021
I have two arrays:
y = [1 1 1 1 1 1.5 1.7 1.9 2 2.7]
x = [25:35]
How can I find the corresponding x value for the first number that breaks the chain in y (in this case 1.5)?
y values are different for each loop but the x is almost stable.
Furthermore, how can I store the x y values of the first value that breaks the chain in a loop. Thank you so much.
Star Strider on 21 Feb 2021
Edited: Star Strider on 21 Feb 2021
y = [1 1 1 1 1 1.5 1.7 1.9 2 2.7];
x = [25:35];
TF = ischange(y,'variance');
Idx = find(TF,1,'first')
Out = x(Idx)
I’m not certain what you want, or how robust this would be to your other data, so you may need to experiment with it.
More Answers (1)
the cyclist on 21 Feb 2021
Because x and y are not the same length, I'm not sure how to make the "correspondence" between them. However, this code snippet will give the index of the first element that is different from the preceding ones:
idx = find(diff(y)~=0,1) + 1;
Maybe you can figure out the rest from there, or explain more about what you mean.