matlab "FoldList" (generalized cumfn)
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Darin
il 18 Set 2020
Commentato: Walter Roberson
il 20 Set 2020
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 Commenti
Risposta accettata
Walter Roberson
il 18 Set 2020
2 Commenti
Walter Roberson
il 19 Set 2020
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.
Più risposte (1)
Darin
il 20 Set 2020
1 Commento
Walter Roberson
il 20 Set 2020
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.
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!