Hourly, Daily, Weekly, averages with accumarray and unique
Show older comments
I have a data set that is set up like this: Column one is a timestamp, column 2 is a start time, column 3 is the end time, and columns 4 to 20 are data. This is a table with 8544 rows and 20 columns.
Time Stamp Start time End Time Data 4:26
89899898 "01/01/16 01:00" "01/01/16 01:59" .09 ... etc
Since this data is in a table, I first converted to an array, and then used unique to specify unique times and accumarray to give me the averages. Problem is, I don't get a value out with "out_hour", I get an error. My "ah" gives me a matrix that is 8544 by 2 columns, with all the start and end times. My "ch" gives me a 8544 row by 1 column matrix. I have a similar set up for the daily and weekly averages. For some reason, "out_hour" doesn't provide me with a value, just an error. Any thoughts?
Data1 = table2array(Data);
%average values per hour
[ah,~,ch] = unique(Data1(:,2:3),'rows');
out_hour = [ah,accumarray(ch,Data1(:,4:26),[],@nanmean)];
Accepted Answer
More Answers (0)
Categories
Find more on Tables in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!