Combine two tables based on date time

37 ビュー (過去 30 日間)
Dion Theunissen
Dion Theunissen 2021 年 8 月 3 日
コメント済み: Peter Perkins 2021 年 8 月 5 日
I have a table A with a datetime (Year, month day and time) and a table B with a datetime(year month day)
Now I have to combine those two tables with each other based on the date. I have to check what date will match from table A to table B and the that index of table B.
For now I have this script, but it doesn't work
check = dir('*.xls');
weatherYear = readtable("/Users/diontheunissen/Documents/Smart_Driver/RawData/weatherYear.xlsx", opts, "UseExcel", false);
Date = datetime(weatherYear.Aug2020);
name = fullfile(check(1).folder, check(1).name);
Ritten = readtable(name, opts, "UseExcel", false);
Datum = datetime(Ritten.Starttijd);
Datum.Format = 'dd-MMM-yyy';
Ritten.Starttijd = Datum;
t1 = datetime(Datum,'InputFormat','yyyy-MM-dd');
t2 = datetime(Date,'Format','yyyy-MM-dd');
[logical_Index ,index] = ismember(t1,t2);
A =
B=
Anyone who can help me?

回答 (1 件)

Scott MacKenzie
Scott MacKenzie 2021 年 8 月 3 日
TT1 = table2timetable(A);
TT2 = table2timetable(B):
TT3 = synchronize(TT1, TT2);
  2 件のコメント
Dion Theunissen
Dion Theunissen 2021 年 8 月 3 日
Check my update, maybe it will be a bit more clear
Peter Perkins
Peter Perkins 2021 年 8 月 5 日
Scott's answer is the right way to do this, although you may want to be more xplicit and specify the target time vector and the method. But I think the defaults do what you want.

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

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by