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?
0 个评论
回答(2 个)
the cyclist
2016-1-20
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
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
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 Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!