MATLAB Answers

How to make a table with date times and durations?

3 ビュー (過去 30 日間)
Oliver Massaad
Oliver Massaad 2021 年 7 月 19 日
回答済み: dpb 2021 年 7 月 19 日
Hi, I have a set of datetimes and durations, and I want to merge them and display them in a table. I just can't figure out how to set the timezones, keep on getting errors. Any help is appreciated, I attached the files for extra clarity.
Thanks!

採用された回答

dpb
dpb 2021 年 7 月 19 日
>> t=table(rampD_start,rampD_end,'VariableNames',{'Start','End'});
>> head(t)
ans =
8×2 table
Start End
____________ ____________
May-03 11:37 May-03 11:55
May-05 11:00 May-05 11:07
May-21 12:00 May-21 12:24
May-25 17:23 May-25 17:43
May-26 11:37 May-26 12:00
May-28 11:39 May-28 12:01
May-31 12:18 May-31 12:41
Jun-02 10:20 Jun-02 10:42
>> t.Span=t.End-t.Start;
Cannot combine or compare a datetime array with a time zone with one without a time zone.
>> t.Start.TimeZone
ans =
0×0 empty char array
>> t.End.TimeZone
ans =
'Europe/Amsterdam'
>> t.Start.TimeZone=t.End.TimeZone;
>> t.Span=t.End-t.Start;
>> head(t)
ans =
8×3 table
Start End Span
____________ ____________ ________
May-03 11:37 May-03 11:55 00:18:00
May-05 11:00 May-05 11:07 00:07:00
May-21 12:00 May-21 12:24 00:24:00
May-25 17:23 May-25 17:43 00:20:00
May-26 11:37 May-26 12:00 00:23:00
May-28 11:39 May-28 12:01 00:22:00
May-31 12:18 May-31 12:41 00:23:00
Jun-02 10:20 Jun-02 10:42 00:22:00
>>
Or, of course, you can remove the TimeZone from both if don't want to keep it.
Alternatively, go back to the creation of the data from which the two datetime arrays came and ensure they're imported the same way to avoid the mismatch in the beginning.

その他の回答 (1 件)

Sameer Pujari
Sameer Pujari 2021 年 7 月 19 日
Table can be found simply using this
T=table(rampD_start,rampD_end,rampD_dur)

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by