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

6 次查看(过去 30 天)
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?
  16 个评论
Torsten
Torsten 2022-8-4
Was I rounding my calculations? I have no idea! Can you please tell me how to calculate in full precision without rounding? In my code, I didn't manipulate anything related to precision.... or maybe I should have?...
You asked "is there a configuration to truncate values or maybe force the trapz function to generate truncated values?" and with my answer I meant: Don't generate truncated values - use trapz as before without truncating or rounding.
But why? can't floating numbers be equal? why wouldn't they?
x1 = 0.33333333333333;
x2 = 1/3;
x1 == x2
ans = logical
0
Here is a discussion about the subject:
Stephen23
Stephen23 2022-8-4
"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.

请先登录,再进行评论。

回答(1 个)

Steven Lord
Steven Lord 2022-8-4
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 个评论
Abdallah
Abdallah 2022-8-4
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

标签

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by