MATLAB Answers

How to calculate the hourly average

5 views (last 30 days)
Pul
Pul on 26 Jan 2021
Edited: Pul on 27 Jan 2021
Hi, I should calculate an hourly average of this file.
This is the start of my script:
clear all
Func=importdata('Matlab.csv');
data_num=Funcdata;
data_str=Func.textdata;
data_str_splitted=split(data_str);
for i=1:length(data_str_splitted)
days_code(i,:)=str2double(erase(data_str_splitted(i,1),"/"));
end
Could anyone give me an advice?
Thank you.
  2 Comments
Rik
Rik on 26 Jan 2021
Why did you flag your question as a duplicate?

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 26 Jan 2021
If you have R2016b or later, this is straightforward:
T1 = readtable('Matlab.csv');
First_5_Rows = T1(1:5,:);
TT1 = table2timetable(T1);
TT1 = retime(TT1, 'hourly','mean');
First_10_Rows = TT1(1:10,:)
producing:
First_10_Rows =
10×3 timetable
Var1 Var2 Var3 Var4
___________________ _______ ______ ______
06/23/2015 01:00:00 -30.195 71.304 159.62
06/23/2015 02:00:00 -30.239 71.288 159.57
06/23/2015 03:00:00 -29.93 71.46 158.83
06/23/2015 04:00:00 -29.922 71.487 157.72
06/23/2015 05:00:00 -29.35 71.939 155.11
06/23/2015 06:00:00 -28.742 72.334 156.36
06/23/2015 07:00:00 -28.336 72.619 158.46
06/23/2015 08:00:00 -28.339 72.436 158.91
06/23/2015 09:00:00 -27.784 72.907 157.82
06/23/2015 10:00:00 -27.128 73.226 153.73
.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!