Problem 750. Accumulate Cells
Given a combining function, a cell array, and an initial value, accumulate the result.
For example,
accumcell(@plus,{1,2,3,4},0)
should return 10, while
accumcell(@times,{1,2,3,4},1)
should return 24.
The elements of C should be such that the combining function can apply to them without generating an error (all the same size, for example).
Solution Stats
Problem Comments
-
2 Comments
Nicholas Howe
on 6 Jun 2012
I'm hoping there is a built-in function I don't know about that solves this problem. Perhaps accumarray?
Maryam HCT2022 Yousef
on 11 Oct 2021
Nice
Solution Comments
Show commentsProblem Recent Solvers43
Suggested Problems
-
Replace NaNs with the number that appears to its left in the row.
2925 Solvers
-
1665 Solvers
-
Project Euler: Problem 3, Largest prime factor
1350 Solvers
-
Join Strings with Multiple Different Delimiters
168 Solvers
-
Area of an equilateral triangle
5815 Solvers
More from this Author11
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!