how to convert data from minute to hourly average

this is the extension of my file which needs to be converted.this is the sample data.there are individual files for each day consisting of 1440 rows and 4 columns.this file is to be read in matlab and processed for 4 years. i need to average the time and data i.e, first two columns of the given table.there are some missing data in which the data is missing but the time is recorded.any program can solve my data.thanks in advance

 Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 16 Mär. 2018
dir1 = 'path_to_folder_with_your_txt_files';
f = dir(fullfile(dir1,'iisc*.txt'));
nm = {f.name}';
dt = datetime(regexp(nm,'\d{4}-\d{2}-\d{2}','match','once'));
TT = [];
for ii = 1:numel(dt)
T = readtable(fullfile(dir1,nm{ii}),'Format','%f%f%f%f','TreatAsEmpty','-');
Time1 = dt(ii) + hours(T.Var1);
TT = [TT;timetable(Time1,T.Var2,'v',{'data'})];
end
TTout = retime(TT,'hourly','mean');
TTout = TTout(~isnan(TTout.data),:);

7 Kommentare

SD
SD am 16 Mär. 2018
sir, this is iisc.std file. how to read this instead of .txt file.igot erroe in t=readtable.can you clarify my doubt.
SD
SD am 16 Mär. 2018
the files i attached are read in notepad or notepad++.these are not in tabular form. so, can you tell me how to read these types of data
Andrei Bobrov
Andrei Bobrov am 16 Mär. 2018
Bearbeitet: Andrei Bobrov am 16 Mär. 2018
I do not know how to import a std-file into MATLAB. Try is function importdata.
SD
SD am 16 Mär. 2018
that's a great help. thank you sir
SD
SD am 16 Mär. 2018
problem solved .thanks for the help
SD
SD am 17 Mär. 2018
sir,can you tell me how to save the output into a seperate folder for which you have given the previous answer.
SD
SD am 17 Mär. 2018
how to do monthly average for the each hour of the seperate day. eg: monthly average of (01/01/2012 0.00 hr,01/02/2012 0.00hr,02/01/2012 0.00hr ............31/01/2012) and also daily average for day time of the universaltime average and night time also

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

KSSV
KSSV am 16 Mär. 2018
YOu can load the text file using load or importdata. To egt hourly mean check the below example code.
t = 1:24*60 ; % time in minutes
A = rand(1,numel(t)); % some random data for 1440 minutes
% Arrange indices into hours
idx = reshape(1:24*60,60,[])' ;
% Arrange data into hours
A_hours = A(idx) ;
% GEt mean
A_hourly_mean = mean(A_hours,2) ;

2 Kommentare

SD
SD am 16 Mär. 2018
sir, i tried your suggested program. but i am getting the random values in the range of 0 & 1.but i need the mean of the data.
KSSV
KSSV am 16 Mär. 2018
A is random data I have taken to demonstrate. You have to used your data.

Melden Sie sich an, um zu kommentieren.

Produkte

Tags

Gefragt:

SD
am 16 Mär. 2018

Kommentiert:

SD
am 17 Mär. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by