Average in a matrix with different intervals

2 visualizaciones (últimos 30 días)
Rodrigo Morais
Rodrigo Morais el 10 de Mzo. de 2017
Editada: Jan el 1 de Oct. de 2017
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 comentarios
Image Analyst
Image Analyst el 10 de Mzo. de 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.
Jan
Jan el 1 de Oct. de 2017
@Rodrigo: It would be useful, if you explain how the "date" is stored.

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 1 de Oct. de 2017
Editada: Jan el 1 de Oct. de 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

Categorías

Más información sobre Time Series Objects en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by