How can one create a timetable with one column (all 1) with beginning date and end date?

1 回表示 (過去 30 日間)
I want to create a timetable T that begins on 1/2/2020 till 5/15/2020. How can one get started?

採用された回答

Wan Ji
Wan Ji 2021 年 8 月 18 日
I have got your idea and write a code for you:
startdate = datetime('2020-01-02');
enddate = datetime('2020-05-15');
dt = enddate - startdate;
dday = hours(dt)/24 + 1;
TT = timetable('StartTime',startdate,...
'TimeStep',caldays(1), 'size',[dday,3],... % 1 day as time step
'VariableTypes',{'double','double','double'},...
'VariableNames', {'Ones', 'Twos', 'Threes'});
TT.Ones(:) = 1;
TT.Twos(:) = 2;
TT.Threes(:) = 3;
You can see timetable is enough to create such a table but a little bit complex.
TT =
135×3 timetable
Time Ones Twos Threes
__________ ____ ____ ______
2020-01-02 1 2 3
2020-01-03 1 2 3
2020-01-04 1 2 3
2020-01-05 1 2 3
2020-01-06 1 2 3
2020-01-07 1 2 3
...
2020-05-11 1 2 3
2020-05-12 1 2 3
2020-05-13 1 2 3
2020-05-14 1 2 3
2020-05-15 1 2 3
  5 件のコメント
Wan Ji
Wan Ji 2021 年 8 月 18 日
Ones = [1;1]; t = datetime({'2020-01-02';'2020-05-15'});
TT = retime(timetable(t,Ones),'daily','linear');
This may be more clear

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTime Series Events についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by