フィルターのクリア

How do I get decimal for the index of the function max()

6 ビュー (過去 30 日間)
Max-Henri Froger
Max-Henri Froger 2020 年 6 月 24 日
コメント済み: Max-Henri Froger 2020 年 6 月 25 日
Hi everyone,
I am using the fonction max() to reveal the maximum of 5 matrixes. I am using the code below:
[y1,x1] = max([max(WheelTorque_1) max(WheelTorque_2) max(WheelTorque_3) max(WheelTorque_4) max(WheelTorque_5)])
y1 =
2.5798e+03
x1 =
4
I checked the maximum on the matrixes and the y1 is correct but the x1 is false. The correct x1 is 4.85. I don't know if matlab does a truncation or if there is another problem.
Thanks for your help!
  5 件のコメント
KSSV
KSSV 2020 年 6 月 24 日
So in that case, if you have absicca.....use
x(x1)
Max-Henri Froger
Max-Henri Froger 2020 年 6 月 25 日
Yes but I don't know how to call to right matrix wheelTorque. Because the index say the maximum is in the WheelTorque_4 but I don't find the way to code this part. Do you know if I could use a system like WheelTorque_(i)(j) and i would be the index and j the x1? Because write like that it doesn't work

サインインしてコメントする。

回答 (1 件)

John D'Errico
John D'Errico 2020 年 6 月 24 日
編集済み: John D'Errico 2020 年 6 月 24 日
The max function does NOT interpolate your data. Just because, IF you looked at the curve, you might decide the true maximum occurs someplace between between two points, max does not find that intermediate location.
Max returns to point in your array that is the maximum element, and the index of that element. No more. You cannot make it do more. Max is what it is. You cannot hope code will do what you want instead of what it is programmed to do.
If you truly need that intermediate point, then your main choice is to use a function that would smoothly interpolate the data. A spline is a common way to do that. And then use a tool like fminbnd or fminsearch to minimize the negative of your function. This will find a maximum.
If you have the underlying function that generated that values, you can use the same tools, fminbnd or fminsearch to minimize the negative of that function. Again, it will locate a max value then. But you cannot just use max.

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by