- Do you receive warning and/or error messages? If so the full and exact text of those messages (all the text displayed in orange and/or red in the Command Window) may be useful in determining what's going on and how to avoid the warning and/or error.
- Does it do something different than what you expected? If so, what did it do and what did you expect it to do?
- Did MATLAB crash? If so please send the crash log file (with a description of what you were running or doing in MATLAB when the crash occured) to Technical Support so we can investigate.
how to calculate hourly averages?
2 views (last 30 days)
Show older comments
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 Comments
Steven Lord
on 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
dt2 = datetime(1e8, 'ConvertFrom', 'epochtime') % 1e8 seconds since Jan 1, 1970
datetime(1970, 1, 1) + seconds(1e8)
Answers (1)
Drishti
on 7 Aug 2024
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')
% Convert the table to a timetable using the datetime column as RowTimes
TT1 = table2timetable(T1, 'RowTimes', 'Time')
% Retime the timetable to hourly with mean aggregation
TT1 = retime(TT1, 'hourly', 'mean')
For more information, you can refer to the MATLAB Documentation given below
I hope this resolves your query.
0 Comments
See Also
Categories
Find more on Tables 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!