Create a timetable for every minute in one day

16 ビュー (過去 30 日間)
Mark Maders
Mark Maders 2021 年 8 月 6 日
編集済み: Scott MacKenzie 2021 年 8 月 6 日
Is it possible to generate a timetable where each row represents one minute throughout the day? A table with a height of 1440 with each row increasing by 1 minute, starting at 00:00:00?
I initially tried it with duration but then realised that duration and timestamps are not the same.
j = 0;
for i = 1:24
T_Daily = duration(j,0:59,0);
All_T_Daily{i} = T_Daily;
j=j+1;
end
T_Daily= horzcat(All_T_Daily{:});
T_Daily = T_Daily.';

回答 (2 件)

Scott MacKenzie
Scott MacKenzie 2021 年 8 月 6 日
編集済み: Scott MacKenzie 2021 年 8 月 6 日
Here you go. As seen in the output from whos, there are 1441 rows in the timetable, one for each minute in the day plus the first minute in the next day.
% create datetime array for Aug 1, 2021 with 1 row per minute
DT = datetime(2021,8,1):minutes(1):datetime(2021,8,2);
% covert to table and add some test data
T1 = array2table(DT');
T1.Data = rand(height(T1),1);
% convert to timetable
TT1 = table2timetable(T1);
whos
Name Size Bytes Class Attributes DT 1x1441 11528 datetime T1 1441x2 24255 table TT1 1441x1 24041 timetable
  2 件のコメント
Mark Maders
Mark Maders 2021 年 8 月 6 日
Can this be done without giving a date? Just focused on the time
Scott MacKenzie
Scott MacKenzie 2021 年 8 月 6 日
編集済み: Scott MacKenzie 2021 年 8 月 6 日
Oops, I jumped the gun on this one. Seems duration is probably not a good choice. See @Star Strider's answer and @Peter Perkins comments.
I still think the timetable arrangement with a datetime column is reasonable, since it gives you one-minute increments throughout the day.

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


Star Strider
Star Strider 2021 年 8 月 6 日
Without a date, it creates a duration array, not a datetime array. The two are different, especially with respect to 'Format' options and other properties.
One possibility:
TT1 = table((0:minutes(1):hours(24)).')
TT1 = 1441×1 table
Var1 ______ 0 min 1 min 2 min 3 min 4 min 5 min 6 min 7 min 8 min 9 min 10 min 11 min 12 min 13 min 14 min 15 min
TT1.Var1.Format = 'hh:mm:ss'
TT1 = 1441×1 table
Var1 ________ 00:00:00 00:01:00 00:02:00 00:03:00 00:04:00 00:05:00 00:06:00 00:07:00 00:08:00 00:09:00 00:10:00 00:11:00 00:12:00 00:13:00 00:14:00 00:15:00
Noon = TT1.Var1(719:722)
Q1 = 4×1 duration array
11:58:00 11:59:00 12:00:00 12:01:00
Using the dateshift funciton is also a possibility for a datetime array.
.
  3 件のコメント
Star Strider
Star Strider 2021 年 8 月 6 日
Simply changing the 'Format' could do what you want, displaying only the times.
For plotting, see the documentation section on Plot Dates and Durations for a detailled description.
.
Peter Perkins
Peter Perkins 2021 年 8 月 6 日
As SS says, datetime is for specific points in time, duration is for elapsed time. You can absolutely use duration as a time of day, but it does not roll over at 24:00:00. So if you are adding thigs to a "time of day" duration, you may need to handle roll over. But of course you will also have to increment the date. Which leads to back to using datetime, probably.

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

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by