How to calculate the hourly average

1 回表示 (過去 30 日間)
Pul
Pul 2021 年 1 月 26 日
編集済み: Pul 2021 年 1 月 27 日
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 件のコメント
Rik
Rik 2021 年 1 月 26 日
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.
Rik
Rik 2021 年 1 月 26 日
Why did you flag your question as a duplicate?

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2021 年 1 月 26 日
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 件のコメント
Pul
Pul 2021 年 1 月 26 日
Thank you very much!
Star Strider
Star Strider 2021 年 1 月 26 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Report Generator についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by