how can we do this?

1 次查看(过去 30 天)
diadalina
diadalina 2018-11-29
编辑: diadalina 2018-12-4
i want to calculate the maximum of vectors éléments and its position using the diff command, can any one help me ?
  2 个评论
John D'Errico
John D'Errico 2018-11-29
Why not just use max? Since it does exactly what you claim to want.
diff as applied to a vector will not help you here.
diadalina
diadalina 2018-11-29
it is another way to calculate the max ?

请先登录,再进行评论。

采纳的回答

madhan ravi
madhan ravi 2018-11-29
[value,index]=max(vector) %use max which does exactly what you want
  7 个评论
Jan
Jan 2018-12-3
编辑:Jan 2018-12-3
@diadaline: Use these three inputs:
a = rand(1, 10)
b = 1:10
c = 10:-1:1
While using max() is easy here, there is no chance to use diff() to find a maximum value. But here, diff can be useful:
d = sin(0:0.001:pi)
Here you have the additional knowledge, that the elements are monotonically increasing and decreasing. Together with this knowledge diff can be used:
find(diff(d) <= 0, 1, 'first')
max() is more useful, because it works in the general case also.
diadalina
diadalina 2018-12-4
thank you mr Jan, now it is clear for me.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by