Filter löschen
Filter löschen

how to calculate hourly averages?

27 Ansichten (letzte 30 Tage)
Laura
Laura am 16 Jul. 2024
Beantwortet: Drishti am 7 Aug. 2024 um 8:24
I convertued my file to a csv, then used the following code to try and get hourly averages:
writematrix(NTU,'M.csv');
T1 = readtable('M.csv');
TT1 = table2timetable(T1,'RowTimes',NTU);
TT1 = retime(TT1, 'hourly','mean');
Am I using table2timetable wrong?
  5 Kommentare
Laura
Laura am 16 Jul. 2024
NTU 2856x1 22848 double
Steven Lord
Steven Lord am 17 Jul. 2024
So what do the values in NTU represent? Seconds since an epoch, days since an epoch, yyyymmdd, etc.?
Use those as inputs to datetime or duration (possibly with 'ConvertFrom' and the appropriate option for what your data represents) then use the datetime or duration array that call returns as your RowTimes. For example:
dt1 = datetime(19850621, 'ConvertFrom', 'yyyymmdd') % June 21, 1985 or
dt1 = datetime
21-Jun-1985
dt2 = datetime(1e8, 'ConvertFrom', 'epochtime') % 1e8 seconds since Jan 1, 1970
dt2 = datetime
03-Mar-1973 09:46:40
datetime(1970, 1, 1) + seconds(1e8)
ans = datetime
03-Mar-1973 09:46:40

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Drishti
Drishti am 7 Aug. 2024 um 8:24
Hi Laura,
As I can conclude that you are trying to use the ‘time2timetable’ and ‘retime’ function on the csv file.
To use the ‘time2timetable’ function, the second parameter should be the time vector, which serves as the row times of the timetable.
The code provided by you uses matrix which is ‘NTU’ as the second parameter and hence leading to the error.
% Write the NTU table to a CSV file
writetable(NTU, 'M.csv');
% Read the CSV file into a table
T1 = readtable('M.csv')
T1 = 25x2 table
Time Data ____________________ ________ 01-Jan-2023 00:00:00 0.48082 01-Jan-2023 01:00:00 0.90551 01-Jan-2023 02:00:00 0.80632 01-Jan-2023 03:00:00 0.76504 01-Jan-2023 04:00:00 0.3527 01-Jan-2023 05:00:00 0.26046 01-Jan-2023 06:00:00 0.3855 01-Jan-2023 07:00:00 0.61901 01-Jan-2023 08:00:00 0.41475 01-Jan-2023 09:00:00 0.53672 01-Jan-2023 10:00:00 0.91554 01-Jan-2023 11:00:00 0.78077 01-Jan-2023 12:00:00 0.67933 01-Jan-2023 13:00:00 0.02752 01-Jan-2023 14:00:00 0.6933 01-Jan-2023 15:00:00 0.034749
% Convert the table to a timetable using the datetime column as RowTimes
TT1 = table2timetable(T1, 'RowTimes', 'Time')
TT1 = 25x1 timetable
Time Data ____________________ ________ 01-Jan-2023 00:00:00 0.48082 01-Jan-2023 01:00:00 0.90551 01-Jan-2023 02:00:00 0.80632 01-Jan-2023 03:00:00 0.76504 01-Jan-2023 04:00:00 0.3527 01-Jan-2023 05:00:00 0.26046 01-Jan-2023 06:00:00 0.3855 01-Jan-2023 07:00:00 0.61901 01-Jan-2023 08:00:00 0.41475 01-Jan-2023 09:00:00 0.53672 01-Jan-2023 10:00:00 0.91554 01-Jan-2023 11:00:00 0.78077 01-Jan-2023 12:00:00 0.67933 01-Jan-2023 13:00:00 0.02752 01-Jan-2023 14:00:00 0.6933 01-Jan-2023 15:00:00 0.034749
% Retime the timetable to hourly with mean aggregation
TT1 = retime(TT1, 'hourly', 'mean')
TT1 = 24x1 timetable
Time Data ____________________ ________ 01-Jan-2023 00:00:00 0.48082 01-Jan-2023 01:00:00 0.90551 01-Jan-2023 02:00:00 0.80632 01-Jan-2023 03:00:00 0.76504 01-Jan-2023 04:00:00 0.3527 01-Jan-2023 05:00:00 0.26046 01-Jan-2023 06:00:00 0.3855 01-Jan-2023 07:00:00 0.61901 01-Jan-2023 08:00:00 0.41475 01-Jan-2023 09:00:00 0.53672 01-Jan-2023 10:00:00 0.91554 01-Jan-2023 11:00:00 0.78077 01-Jan-2023 12:00:00 0.67933 01-Jan-2023 13:00:00 0.02752 01-Jan-2023 14:00:00 0.6933 01-Jan-2023 15:00:00 0.034749
For more information, you can refer to the MATLAB Documentation given below
I hope this resolves your query.

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by