How can I manipulate a matrix based on its elements?

1 view (last 30 days)
So I have a matrix of time values in the form of date/time values from Excel. I subtracted the first element of the vector of dates from each element, which yields elements for the year's worth of dates going from 0 to 365. These numbers are broken into 5 minute time intervals, i.e.,
41709.416666667
41709.420138889
41709.423611111
41709.427083333
41709.430555556
41709.434027778
41709.437500000
41709.440972222
41709.444444444
41709.447916667
41709.451388889
41709.454861111
41709.458333333
41709.461805556
41709.465277778
41709.468750000
41709.472222222
41709.475694444
41709.479166667
And so on. I have a corresponding value associated with each date, an amount. I want to sum up the amounts in the corresponding vector of values for each day, so get 365 sums. I want to be able to sum up those values based on the integer increasing in the date matrix by one, because each day does not necessarily have the same number of measurements. Thus, in the end I want a matrix of 365 dates with 365 sums consisting of the result of adding up the precise number of measurements, taken approximately every 5 minutes each day.
  2 Comments
Vivek
Vivek on 2 Oct 2015
Happy to try to answer your question - but I do not understand exactly the format your data is in. Are you saying that you have 365 rows worth of data with a different number of observations for each row, and you want to obtain the sum for each row?
Arianna K
Arianna K on 3 Oct 2015
I have thousands of rows of data, but multiple measurements from each day, so only 1 to 365, just with about 200 measurements for each day. I want the sum for each day. Measurements are taken about every 5 minutes and I want the total sum of these values. Thank you so much!

Sign in to comment.

Accepted Answer

Matt J
Matt J on 2 Oct 2015
Edited: Matt J on 2 Oct 2015
Sounds like it would be
dailySums = accumarray(Day(:),Val(:))
where Day(i) = 1 to 365 depending on which day the i-th data point is acquired. Likewise, val(i) is the value of the i-th data point.
  9 Comments
Matt J
Matt J on 16 Oct 2015
Well, again, there is only one place in STREAMWETLAND (line 32) that the problem could be coming from. You haven't given 'dates' in a format that datetime() expects,
Arianna K
Arianna K on 16 Oct 2015
Thank you so much for all your help! I had a few more issues, but I have gotten them all hammered out now, and I have an accurate output document with the daily sums for my data!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!