matlab "FoldList" (generalized cumfn)
Mostrar comentarios más antiguos
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 comentarios
madhan ravi
el 18 de Sept. de 2020
Could you provide an example?
Darin
el 19 de Sept. de 2020
Respuesta aceptada
Más respuestas (1)
Darin
el 20 de Sept. de 2020
0 votos
1 comentario
Walter Roberson
el 20 de Sept. de 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.
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!