# find(V==ma​x(V),1,'fi​rst') returns index that is way beyond the first index where X reaches the maximum

3 views (last 30 days)
Abdallah on 4 Aug 2022
Commented: Stephen23 on 4 Aug 2022
find(V==max(V),1,'first') returns index that is way beyond the first index where V reaches the maximum. In the above picture, you can see that the curve reaches its maximum and plateaus. However, when I run find(X==max(X),1,'first') in the console, I get this: Where's the error?
Stephen23 on 4 Aug 2022
"But why? can't floating numbers be equal?
Of course they can be equal. That does not mean that they will be equal.
"why wouldn't they?"
Because of how floating point error accumulates during any arithmetic using binary floating point numbers.

Steven Lord on 4 Aug 2022
What are the sizes of the variables involved in creating your plot above, and what is the exact syntax for the plot function that you used in creating it?
If the X data for your plot was not the integers 1 through the number of values in the Y data then the index of the point with X coordinate 363 may be greater than 363. In the example below, index is not 1 but the value stored in the X array at that index is 1.
X = 0:0.25:2
X = 1×9
0 0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000
index = find(X == 1) % Will be > 1
index = 5
coordinate = X(index) % Will be 1
coordinate = 1
##### 1 CommentShowHide None
Abdallah on 4 Aug 2022
What are the sizes of the variables involved in creating your plot above what is the exact syntax for the plot function that you used in creating it
plot(linspace(1,1441-(T_B+1)+1,1441-(T_B+1)+1),I_B)
If the X data for your plot was not the integers 1 through the number of values in the Y data .... As we can see, the X data are indeed the integers 1 through the number of values in the Y data, since I_B has 1341 column (as displayed above).
So ""then the index of the point with X coordinate 363 may be greater than 363"" isn't correct.

R2017b

### Community Treasure Hunt

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

Start Hunting!