Find a function that sorts each ith element in the vector by the largest of the preceding elements.

1 visualización (últimos 30 días)
Let x = [x_1, x_2, x_3, ..., x_N].
I want to make a vector y whose ith element is given as y_i = max {x_k | k<=i}.
For example, suppose that x is given as x=[1, 8, 3, 9, 11].
Then, I want to make y=[1, 8, 8, 9, 11].
Is there a function that does as above?
Actually, I can make a function that does as above, but I want to use built-in functions since the built-in functions are usually faster than my own.
Thank you for reading my question.
  3 comentarios

Iniciar sesión para comentar.

Respuestas (1)

Steven Lord
Steven Lord el 17 de Dic. de 2019
The cummax function computes the cumulative maximum of an array.

Categorías

Más información sobre Shifting and Sorting Matrices 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