How to average seconds data to minutes data?

조회 수: 1 (최근 30일)
Gnanamoorthy P
Gnanamoorthy P 2020년 11월 6일
댓글: Steven Lord 2020년 11월 6일
I have a one Hz set of data for whole day, so i would like to average this seconds data into each minutes data. Please give your code and suggestions.
Thanks you.

답변 (1개)

Dave B
Dave B 2020년 11월 6일
It sounds like you want to use the first column of your CSV which has times, and for each minute extract compute the average of the remaining columns.
I'll use tables and groupsummary (introduced in 2018a) which are great for this kind of problem:
tbl = readtable('PGM.csv'); % Read the data in
% Convert first column to a datetime the date part is arbitrary here (because they're not
% supplied in the file), but it's so easy to do this with the datetime type!
tbl.Var1 = datetime(tbl.Var1,'InputFormat','HH:mm');
result=groupsummary(tbl,"Var1","minute","mean",["Var2" "Var3" "Var4" "Var5"]);
% The results for the 4 columns are in result.mean_Var2, result.mean_Var3 etc.
% Additional notes:
% You can strip off the date part and go back to a string using:
dt = extractAfter(string(result.minute_Var1)," ");
% You could plot the first column of data with:
plot(datetime(extractAfter(string(result.minute_time),"" "")),result.mean_Var2)
A great feature of groupsummary,is that if you wanted some other summary statistics in addition to mean those are easy to get in the same shot, see the documentation for details.
  댓글 수: 2
Gnanamoorthy P
Gnanamoorthy P 2020년 11월 6일
Thank you very much,.. Now you have sloved my problem.
Steven Lord
Steven Lord 2020년 11월 6일
Another alternative would be to store the data in a timetable and use retime.

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

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by