Sum e columns together without a for loop.
Show older comments
So I let say there a matrix like this
b = [1 2 3 4 5 6 7 8 9; 1 2 3 4 5 6 7 8 9; 1 2 3 4 5 6 7 8 9]
I want to change b into a matrix like this
b = [6 15 24; 6 15 24; 6 15 24]
So I'm add summing up the columns, but only 3(e) at a time, leaving me with a matrix that used to be nxm but is now nx(m/e).
Currently, I'm doing this with a for loop where I just take every 3 columns together to make a new column and update the field of a preallocated matrix of size nx(m/3). However, I realize that I need to make it work for any e(not just 3) and because of this, and the large datasets I will be dealing with(both n and m are large), I need to be able to do this without a for loop.
Is there some built in function that will help me? I've tried going through the documentation but I can't seem to find anything that will work.
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!