How to calculate maximum up to current point?
1 次查看(过去 30 天)
显示 更早的评论
Hi, how can i calculate the an array of current maxima, i.e. for each point in the array to calculate the maximum from the first observation of the array to the current? e.g. for array [3 8 10 6] i want the output to be [3 8 10 6] ?
Is there a function to do this (movmax i think it works for a fixed lookback or lookforward) or do i just need to loop through all observations?
2 个评论
回答(2 个)
John D'Errico
2017-8-18
cummax([3 8 10 6])
ans =
3 8 10 10
2 个评论
John D'Errico
2017-8-18
I keep learning new things on Answers. New little goodies that appeared when I was not watching. I guess we all should read the release notes religiously. That would take all the fun out of it though. :)
José-Luis
2017-8-18
a = [3,8,10,6,5,11,12,-20];
n = numel(a);
result = tril(bsxfun(@minus,a,a'));
[~,idx] = max(result,[],2);
result = a(idx)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!