How do I calculate the daily average for a large data set?
4 views (last 30 days)
Show older comments
I have stored the date in variable with year, month, day, hour, minute, and second. I have a another vector with significant wave height with the same number of rows. However, it is possible for days to have different numbers of data points. I would like to produce a plot with the day of the month and the average of the significant wave height for each day within the set. In Excel, I can use a pivot table. How do I perform the same function in Matlab?
0 Comments
Answers (2)
the cyclist
on 20 Jan 2016
If you upload your data (or a representative segment of it), someone here could give you some more specific advice on how to use it.
the cyclist
on 21 Jan 2016
You need to do three things:
- Import the data
- Convert your y/m/d columns into their unique datenums (which you can do with the datenum command)
- Get the daily mean (which you can do with accumarray)
Here is a code snippet that shows you how to do the last step:
% List of your date numbers
dateList = [736350; 736350; 736350; 736351; 736351; 736352; 736352; 736352];
% Corresponding values
value = [ 1; 2; 3; 4; 5; 6; 7; 8];
% Get the unique dates, and their indices
[uniqueDays,idxToUnique,idxFromUniqueBackToAll] = unique(dateList);
dailyMean = accumarray(idxFromUniqueBackToAll,value,[],@mean);
If you can't figure out the other two steps, perhaps post another question.
1 Comment
mdi
on 1 Aug 2018
hi there, I was looking to do so and couldn`t figure out the last two steps, can you elaborate, please? and in addition, can you please in which time format I should load the data? for now all my data are stored in .csv files in the general format.
thanks in advance
See Also
Categories
Find more on Dates and Time 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!