How do I calculate the daily average for a large data set?

4 views (last 30 days)
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?

Answers (2)

the cyclist
the cyclist on 20 Jan 2016
You should be able to use the accumarray function.
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.
  1 Comment
Rodney Dwyer
Rodney Dwyer on 20 Jan 2016
the cyclist thank you for your response. Here is a short sample of the spread sheet that has the rows and columns I need. Ideally I would like to get a daily average for the significant wave height and a daily max for the the max height.

Sign in to comment.


the cyclist
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
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

Sign in to comment.

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!