MATLAB: I want to sum specific element from a row vector

for loopsum

I have a row vector of 14752×1 which is a preciitation(pre) data from 1980 to 2020. I want my for loop to sum the range from 1:365 for each year like this p = [sum(pre(1:365,1)) sum(pre(366:731,1)) sum(pre(730:1090,1)) sum(pre(1090:1450,1)…] but my for loop is calculating the sum of each year precipitation but not storing them in the workplace it only gives me 1 numerical value.
for i = 1:365:length(pre)-365
pp = sum(pre(i+1:i+365,1))
end
Thank you for the help

Best Answer

Wanted = sum(reshape(pre(:,1),365,[]))
Related Question