# how can we do this?

1 view (last 30 days)
Edited: diadalina on 4 Dec 2018
i want to calculate the maximum of vectors éléments and its position using the diff command, can any one help me ?

John D'Errico on 29 Nov 2018
Why not just use max? Since it does exactly what you claim to want.
it is another way to calculate the max ?

madhan ravi on 29 Nov 2018
[value,index]=max(vector) %use max which does exactly what you want

mr ravi what do you want to say by the monotonicity of the vector can you more explain to me please ?
Jan on 3 Dec 2018
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.
thank you mr Jan, now it is clear for me.