hourly mean for my data?

2 views (last 30 days)
TV Reddy Gireesh
TV Reddy Gireesh on 11 Aug 2017
Commented: TV Reddy Gireesh on 31 Aug 2017
hello sir, im new to matlb, i have a data set like datenum(or)datevec + data in one matrics for example
7.3685e+005 656 756 ....
7.3685e+006 621 736....
.
.
(or)
2017 05 1 656 756 ....
2017 05 1 621 736....
.
.
like that for 24 hrs and with 5min interval i want hourly mean data, and i have tried unique command and others to filter it's not coming properly, note: some time data gap will be there but in file it will continued like 00:50 13:30 gap is there like almost 13 hours, please help out this, thanking you,
thanks in advance

Accepted Answer

Jan
Jan on 11 Aug 2017
Edited: Jan on 11 Aug 2017
It is easier with the datenum format. Start with defining hours:
Time = data(:, 1); % Hop this matches your data
Hour = floor(Time * (24 * 60));
[uH, iH, iuH] = unique(Hour);
Now splitapply or accumarray will help, but I suggest a dull loop at first:
MeanData = zeros(numel(uH), size(data, 2) - 1);
for k = 1:numel(uH)
MeanData(k, :) = mean(data(iuH == k, 2:end), 1);
end
With modern functions:
MeanData = splitapply(@myMean1, data(:, 2:end), iuH);
function m = myMean1(x)
m = sum(x, 1) / size(x, 1);
I used an external function myMean1 instead of simply @mean, because mean() would operate over the 2nd dimension, if only one value is existing for a certain hour. An anonymous function would do the trick also, but slower.
By the way: If you have a modern Matlab version, take a look to the new datetime class.
Note: The code is untested due to the lack of input data.
  2 Comments
TV Reddy Gireesh
TV Reddy Gireesh on 16 Aug 2017
thanks for your help, as u describe that this code is working for only datevec(24/colums) not in datenum(288/coluns) for me. (i have used unique early but facing below problem) But my data is not continuously available 24 hours,only datestamp will be available in data sheet for data gap ,but data will be in empty because of my instrument stabilization time for example 2017 05 1 17 40 02 656 756 .... 2017 05 1 17 45 02 551 226... 2017 05 1 17 50 02 .... 2017 05 1 17 55 02 ... 2017 05 1 18 00 02 .... 2017 05 1 18 05 02 621 736... 2017 05 1 18 10 02 656 756 .... 2017 05 1 18 15 02 621 736... in this data is arranged and gap is there is form 3 to 5th row and in this case above code is making 17th hour and 18th hour both are "NaN" values in this case i'm loosing the mean for 17th hour and 18th hour because of 3 pints (data gap is not consistent it can come any time in the day some times more than 3 times)but i want to skip the empty values and make the remaining values of mean values,
thanking you sir, -gireesh
TV Reddy Gireesh
TV Reddy Gireesh on 31 Aug 2017
hi Jan Simon thanks for answer to me and for the same data set how can i do 2 hr or 3hr mean to my data.......! can you please help me out of this! thanking you., -gireesh

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!