Average in a matrix with different intervals

2 次查看(过去 30 天)
I've got a 104410 value matrix (104410x2) with date and measurements. I want to treat these values by starting to do an average per day. In 2014 a new system was installed and now the measurements were done once per hour. But in some days there are more than 24 values per day, because of inspections or some more testing were done in that day or even with the change to summer time the measurements in that day are 23. How can I calculate the average per day in this matrix, when i've got different intervals per day?
I already tried to reshape the matrix according to the intervals but couldnt quite get the code working.
I know that somehow i need to correlate the specific date with the average made...
Thanks in advance! Rodrigo
  2 个评论
Image Analyst
Image Analyst 2017-3-10
Do you have the latest MATLAB with its much easier time and date functions? Please attach your data so we can see the exact form it takes.
Jan
Jan 2017-10-1
@Rodrigo: It would be useful, if you explain how the "date" is stored.

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2017-10-1
编辑:Jan 2017-10-1
Assuming the that the date and time is stored as datenum:
Date = linspace(datenum('01-Jan-2017'), datenum('01-Jul-2017'), 1000);
Data = [Date.', rand(1000, 1)];
Day = floor(Data(:, 1)); % The day is the integer part of DATENUM
[uDay, ~, index] = unique(Day); % Get unique list of days
Avg = accumarray(index, Data(:, 2), [], @mean); % Mean over values for each day
This would work with a simple loop also:
Day = floor(Data(:, 1)); % The day is the integer part of DATENUM
uDay = unique(Day); % Get unique list of days
Avg = zeros(size(uDay));
for k = 1:numel(uDay)
index = (Day == uDay(k));
Avg(k) = mean(Data(index, 2));
end

类别

Help CenterFile Exchange 中查找有关 Time Series Objects 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by