Be the first to rate this file! 97 downloads (last 30 days) File Size: 1.42 KB File ID: #24391

Aggregate data using any number of multiple columns

by Jeff Burkey

 

09 Jun 2009 (Updated 14 Oct 2009)

Code covered by BSD License  

Using two of Matlabs functions, unique and accumarray, this function summarizes any number of cols.

Download Now | Watch this File

File Information
Description

Surprisingly, I never came across the simple solution of aggregating data using accumarray. Accumarray needs indices supplied to aggregate too. Combining this with the Unique function, the user can quickly and conveniently aggregate data using any available and appropriate funciton supported by Accumarray. The indices are created using the unique function.

This function is especially useful for aggregating timeseries of data say from hourly to daily, monthly, seasonal, etc. Like summing up precipitation, or averaging flow rates, etc.

Expected inputs is a timeseries of data with all but the last column used for generate unique combinations, and the last column is what the summarization is done on.

Additionally, I wrote a similar function (accumSeasonTS.m) aggregating data to seasons as defined by the solstices and equinoxes when given two columns of data: serial date and associated data values.

datain = r x c
fn = supplied string specifying a valid summary statistic function.
Example: @sum, @max, @min, etc.

dataout = r x c

Written by:
  Jeff Burkey
  King County- DNRP
  email: jeff.burkey@kingcounty.gov
  June 9, 2009

Syntax:
  [dataout] = accumTS(datain,fn)
Example:
    d = accumTS(din,@max);

MATLAB release MATLAB 7.8 (R2009a)
Zip File Content  
Other Files accumTS.m,
license.txt
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
14 Oct 2009 John D'Errico

I might point out that this is identical to what the already existing function consolidator does. In addition, consolidator allows a tolerance for floating point data.

http://www.mathworks.com/matlabcentral/fileexchange/8354

Please login to add a comment or rating.
Updates
20 Jun 2009

Changed online text.

14 Oct 2009

Updated comments.

Tag Activity for this File
Tag Applied By Date/Time
statistics Jeff Burkey 10 Jun 2009 09:26:30
aggregate Jeff Burkey 10 Jun 2009 09:26:30
aggregate function Jeff Burkey 10 Jun 2009 09:26:30
accumarray Jeff Burkey 10 Jun 2009 09:26:30
unique Jeff Burkey 10 Jun 2009 09:26:30
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com