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

3 次查看(过去 30 天)
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?

回答(2 个)

the cyclist
the cyclist 2016-1-20
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 个评论
Rodney Dwyer
Rodney Dwyer 2016-1-20
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.

请先登录,再进行评论。


the cyclist
the cyclist 2016-1-21
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 个评论
mdi
mdi 2018-8-1
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by