matlab "FoldList" (generalized cumfn)
3 ビュー (過去 30 日間)
古いコメントを表示
Is there a Matlab equivalent to the Mathematica FoldList function (a generalization of cumsum, cummax, etc., with an arbitrary function).
One could clearly write one, but presumably a built in (such as arrayfun) would be much more efficient. True?
2 件のコメント
採用された回答
Walter Roberson
2020 年 9 月 18 日
2 件のコメント
Walter Roberson
2020 年 9 月 19 日
I see what you mean. No, there is no Mathworks provided function for that.
By the way, for a long time arrayfun was a .m file that looped at the MATLAB level. In those days, arrayfun was faster than a loop only for a very restricted set of functions, and based upon some optimizations that were done for functions but not for scripts. MATLAB improved optimization overall, and arrayfun became no faster than looping... until, that is, arrayfun got converted to a built-in.
その他の回答 (1 件)
Darin
2020 年 9 月 20 日
1 件のコメント
Walter Roberson
2020 年 9 月 20 日
Hypothetically, a built-in function for the purpose could build the execution environment for the anonymous function only once, reducing the execution overhead a little. Anonymous functions are slower than regular function (more overhead to invoke them) so it could potentially help a bit.
A "fold" operation that was only emitting a single output (not the "foldList" that you are hoping for, which collects all of the outputs) could potentially also optimize to use in-place update operations. But probably wouldn't do that.
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!