Daily mean through long time

조회 수: 1 (최근 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 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