"Not sure where this is going wrong."
Reinventing the wheel by writing lots of loops, and ignoring the inbuilt tools.
dt = datetime(2022,2,1,[1;2;2;3],0,0);
pw = [4;5;2;1];
tbl = table(dt,pw)
out = groupsummary(tbl,"dt","sum")
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!