find(V==max(V),1,'first') returns index that is way beyond the first index where X reaches the maximum
3 views (last 30 days)
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?
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
index = find(X == 1) % Will be > 1
coordinate = X(index) % Will be 1