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

1 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

回答(1 个)

Steven Lord
Steven Lord 2019-12-17
The cummax function computes the cumulative maximum of an array.

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by