Search code examples
arraysmatlabsumfunction-handle

Passing sum function matlab and add column wise sum


Is it possible to pass the sum function and declare how to summarize the values? So column or row wise? Like I call the function without passing:

y = sum(x,2);

I want to call an Aggregation function like this, but operate in the rows:

Output = Aggregate(Input,@sum);

Solution

  • Depends a little on how Aggregate uses the function handle it's being passed, but the following should work

    Output = Aggregate(Input,@(x)sum(x,2));