Using the sum function

2 views (last 30 days)
Farai Mwashita
Farai Mwashita on 28 Oct 2014
Commented: Andrew Reibold on 28 Oct 2014
Hello
I have a variable dailyHDD=(1x365) which represents the daily temperature for each day of the year. I am trying to calculate the total for each month and I am not sure sure to do it, In this column 1-31 will be january month. please can you assist on how to break this into 12 months and calculate the total for each month.
Regards
Farai
  1 Comment
Andrew Reibold
Andrew Reibold on 28 Oct 2014
....You say the 'total' for each month as if you want the sum. Your situation however makes it sound more practical to have the mean.
Do you really want the sum?

Sign in to comment.

Answers (1)

Matt J
Matt J on 28 Oct 2014
Edited: Matt J on 28 Oct 2014
[~,m]=datevec(1:365);
totals=accumarray(m,dailyHDD(:))

Community Treasure Hunt

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

Start Hunting!