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

 채택된 답변

Jan
Jan 2017년 8월 11일
편집: Jan 2017년 8월 11일

0 개 추천

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

TV Reddy Gireesh
TV Reddy Gireesh 2017년 8월 16일
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 2017년 8월 31일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Calendar에 대해 자세히 알아보기

질문:

2017년 8월 11일

댓글:

2017년 8월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by