How can I sum arrays internally to get a new array using a loop.

2 views (last 30 days)
So i have an array of 1x5000+ numbers. It is formed in a way so every 288 numbers is one day. I need to shorten my array so that it adds up 288 numbers and loops until in the end i have an array of only days. right now the numbers are in 5 min intervals. And these are in cells that was transfered from an excel file so I need it to be able to work with that.

Accepted Answer

Matt J
Matt J on 27 Apr 2022
Edited: Matt J on 27 Apr 2022
yourVector=rand(1,288*50);
days=sum(reshape(yourVector,288,[]));
whos yourVector days
Name Size Bytes Class Attributes days 1x50 400 double yourVector 1x14400 115200 double
  3 Comments
Matt J
Matt J on 27 Apr 2022
Edited: Matt J on 27 Apr 2022
It means you don't have an even multiple of 288 data entries -- an incomplete day at the end. If you want to sum this day regardless, simply zero-pad
N=numel(yourVector);
M=ceil(N/288)*288;
yourVector(N+1:M)=0;
days=sum(reshape(yourVector,288,[]));

Sign in to comment.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!