Create a timetable for every minute in one day
조회 수: 9 (최근 30일)
이전 댓글 표시
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.';
댓글 수: 0
답변 (2개)
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
댓글 수: 2
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
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.Var1.Format = 'hh:mm:ss'
Noon = TT1.Var1(719:722)
.
댓글 수: 3
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
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 Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!