From discrete dates to continuous dates (revised)

조회 수: 2 (최근 30일)
alpedhuez
alpedhuez 2020년 12월 8일
편집: alpedhuez 2020년 12월 8일
I have a timetable T like
city date visitors
-----------------------
NY January 1 2020 100
NY January 5 2020 40
NY January 12 2020 300
SF January 1 2020 70
SF January 6 2020 240
SF January 15 2020 30
I want to embed this in a larger table with continuous dates such as
city date visitors
-----------------------
NY January 1 2020 100
NY January 2 2020 NaN
NY January 3 2020 NaN
NY January 4 2020 Nan
NY January 5 2020 40
...
How can one do this?
  댓글 수: 3
the cyclist
the cyclist 2020년 12월 8일
Can you upload the table you have in a MAT file, so that we don't have to guess at the date format?
Also, am I to understand that you do not want "2020" to appear in the added dates?
alpedhuez
alpedhuez 2020년 12월 8일
Thank you. They are timetables. I have edited the question text.

댓글을 달려면 로그인하십시오.

채택된 답변

Steven Lord
Steven Lord 2020년 12월 8일
Here's a sample timetable.
dt = datetime(2020, 1, [1; 5; 12]);
T = timetable(dt, [100; 40; 300], 'VariableNames', "visitors");
T.Properties.DimensionNames{1} = 'date'
T = 3x1 timetable
date visitors ___________ ________ 01-Jan-2020 100 05-Jan-2020 40 12-Jan-2020 300
retime it either filling rows not appearing in the original with missing (the default) or with the constant 0
T_fillWithMissing = retime(T, 'daily')
T_fillWithMissing = 12x1 timetable
date visitors ___________ ________ 01-Jan-2020 100 02-Jan-2020 NaN 03-Jan-2020 NaN 04-Jan-2020 NaN 05-Jan-2020 40 06-Jan-2020 NaN 07-Jan-2020 NaN 08-Jan-2020 NaN 09-Jan-2020 NaN 10-Jan-2020 NaN 11-Jan-2020 NaN 12-Jan-2020 300
T_fillWith0 = retime(T, 'daily', 'fillwithconstant', 'Constant',0)
T_fillWith0 = 12x1 timetable
date visitors ___________ ________ 01-Jan-2020 100 02-Jan-2020 0 03-Jan-2020 0 04-Jan-2020 0 05-Jan-2020 40 06-Jan-2020 0 07-Jan-2020 0 08-Jan-2020 0 09-Jan-2020 0 10-Jan-2020 0 11-Jan-2020 0 12-Jan-2020 300
  댓글 수: 1
alpedhuez
alpedhuez 2020년 12월 8일
Thank you. I have edied the question that generalizes the previous question.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Timetables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by