I want to sum specific element from a row vector

1 view (last 30 days)
I have a row vector of 14752x1 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

Accepted Answer

madhan ravi
madhan ravi on 5 Jun 2020
Wanted = sum(reshape(pre(:,1),365,[]))

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!