how can we do this?

1 visualización (últimos 30 días)
diadalina
diadalina el 29 de Nov. de 2018
Editada: diadalina el 4 de Dic. de 2018
i want to calculate the maximum of vectors éléments and its position using the diff command, can any one help me ?
  2 comentarios
John D'Errico
John D'Errico el 29 de Nov. de 2018
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 el 29 de Nov. de 2018
it is another way to calculate the max ?

Iniciar sesión para comentar.

Respuesta aceptada

madhan ravi
madhan ravi el 29 de Nov. de 2018
[value,index]=max(vector) %use max which does exactly what you want
  7 comentarios
Jan
Jan el 3 de Dic. de 2018
Editada: Jan el 3 de Dic. de 2018
@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 el 4 de Dic. de 2018
thank you mr Jan, now it is clear for me.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by