Daily mean through long time

2 ビュー (過去 30 日間)
Nada
Nada 2024 年 12 月 21 日
コメント済み: Star Strider 2024 年 12 月 21 日
Hi All
The variable, the year, the month, the day, the hour, and the minutes are all in a data file.
i need to find a loop that can find out the variable's daily average.
Pay attention to the point that the variable has 24 values during the day. This means that it changes every hour.
Please help me create a loop so that I can find the average daily value for the month and year.

採用された回答

Star Strider
Star Strider 2024 年 12 月 21 日
T1 = readtable('data.xls') % Import Data
T1 = 17280x6 table
YYYY mm ddd HH mint avs ____ __ ___ __ ____ _____ 2012 1 12 0 30 1.12 2012 1 12 1 30 2.12 2012 1 12 2 30 3.12 2012 1 12 3 30 4.12 2012 1 12 4 30 5.12 2012 1 12 5 30 6.12 2012 1 12 6 30 7.12 2012 1 12 7 30 8.12 2012 1 12 8 30 9.12 2012 1 12 9 30 10.12 2012 1 12 10 30 11.12 2012 1 12 11 30 12.12 2012 1 12 12 30 13.12 2012 1 12 13 30 14.12 2012 1 12 14 30 15.12 2012 1 12 15 30 16.12
DateTime = datetime([T1{:,1:5} zeros(size(T1,1),1)]); % Create ‘datetime’ Array From Available Data & Add ‘zeros’ Vector Of Seconds
T1 = removevars(T1, 1:5); % Remove Original Datee & Time Data
T1 = addvars(T1, DateTime, Before=1) % Add New ‘datetime’ Array
T1 = 17280x2 table
DateTime avs ____________________ _____ 12-Jan-2012 00:30:00 1.12 12-Jan-2012 01:30:00 2.12 12-Jan-2012 02:30:00 3.12 12-Jan-2012 03:30:00 4.12 12-Jan-2012 04:30:00 5.12 12-Jan-2012 05:30:00 6.12 12-Jan-2012 06:30:00 7.12 12-Jan-2012 07:30:00 8.12 12-Jan-2012 08:30:00 9.12 12-Jan-2012 09:30:00 10.12 12-Jan-2012 10:30:00 11.12 12-Jan-2012 11:30:00 12.12 12-Jan-2012 12:30:00 13.12 12-Jan-2012 13:30:00 14.12 12-Jan-2012 14:30:00 15.12 12-Jan-2012 15:30:00 16.12
TT1 = table2timetable(T1); % Converet To ‘timetable’
TT1 = retime(TT1, 'daily', 'mean') % Calculate & Show Results
TT1 = 720x1 timetable
DateTime avs ___________ ______ 12-Jan-2012 12.62 13-Jan-2012 36.62 14-Jan-2012 42.862 15-Jan-2012 25 16-Jan-2012 25 17-Jan-2012 25 18-Jan-2012 25 19-Jan-2012 25 20-Jan-2012 19 21-Jan-2012 1 22-Jan-2012 1 23-Jan-2012 1 24-Jan-2012 1 25-Jan-2012 1 26-Jan-2012 1 27-Jan-2012 1
[t1,t2] = bounds(T1.DateTime(T1.avs >= 5))
t1 = datetime
12-Jan-2012 04:30:00
t2 = datetime
20-Jan-2012 17:30:00
figure
plot(T1.DateTime, T1.avs, DisplayName='Original Data')
hold on
stairs(TT1.DateTime, TT1.avs, DisplayName='Daily Mean', LineWidth=2)
hold off
grid
xlim([t1 t2]+[-1 1]*days(3))
xlabel('Time')
ylabel('avs')
legend(Location='SW')
.
  2 件のコメント
Nada
Nada 2024 年 12 月 21 日
Thank you for your assistance. It was very helpful in my instance.
Star Strider
Star Strider 2024 年 12 月 21 日
As always, my pleasure!

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2024 年 12 月 21 日

build a timetable() from the data. Use retime()

  1 件のコメント
Nada
Nada 2024 年 12 月 21 日
Thank you Walter

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by