Average in a matrix with different intervals
3 views (last 30 days)
Show older comments
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 Comments
Image Analyst
on 10 Mar 2017
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.
Answers (1)
Jan
on 1 Oct 2017
Edited: Jan
on 1 Oct 2017
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
0 Comments
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!