How to calculate the hourly average
2 views (last 30 days)
Show older comments
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
on 26 Jan 2021
Why don't you first start looking for a way to import your data that makes use of Matlab data types? Have you looked for a function that will read csv files?
It is good to try to write things yourself, but especially when you start using Matlab you should try to see what tools Matlab provides you with.
Accepted Answer
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
.
2 Comments
More Answers (0)
See Also
Categories
Find more on MATLAB Report Generator in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!