Effacer les filtres
Effacer les filtres

Can you synchronize two or more timetables if each timetable has a different number of rows and columns?

16 vues (au cours des 30 derniers jours)
I have 8 csv files with different types of sensor data. 5 of the files have 3 columns (variables) and 3 of the files have 14 columns. The one column that all the files share is UTC Time. Each file has a different number of rows. Is it possible to use timetables and synchronize to create a single table sorted by time that would then be written to a new csv file? What other MATLAB commands/features might be helpful here? Thank you-
  1 commentaire
dpb
dpb le 3 Oct 2023
The description of synchronize says it "collects the variables from all input timetables, synchronizes them to a common time vector, and returns the result as a single timetable. ... In effect, synchronize horizontally concatenates the variables of [the input timetables] even when they have row times that differ. As a result, synchronize inserts a missing data indicator in [the output timetable wherever there are missing data from one table at an input time]. If [input timetables] have variables with the same names, then synchronize renames them and copies [all] variables into [the output timetable]."
If that's what you want to happen, then "yes".
Otherwise, you may want to look at the various join functions.

Connectez-vous pour commenter.

Réponse acceptée

SAI SRUJAN
SAI SRUJAN le 9 Oct 2023
Hi Nina Sweeney,
I can understand that you want to synchronize two or more timetables using MATLAB commands/features.
You can follow the below given example.
Suppose there are two timetables that have different rows and columns. "timetable1" consists of 3 rows and 1 column, while "timetable2" has dimensions of 4 rows and 2 columns. If we combine the two timetable arrays using "synchronize",the resulting timetable will encompass six rows and three variables.
dt1 = datetime('today')+(-1:1).'; % 3x1 datetime array
dt2 = datetime('today')+(-1:2).'+ 2; % 4x1 datetime array
timetable1=timetable(dt1,[1;2;3]); % 3x1 timetable
timetable2=timetable(dt2,[4;5;6;7],[8;9;10;11]); % 4x2 timetable
TT1=synchronize(timetable1,timetable2) % 6x3 timetable
TT1 = 6×3 timetable
dt1 Var1_timetable1 Var1_timetable2 Var2 ___________ _______________ _______________ ____ 08-Oct-2023 1 NaN NaN 09-Oct-2023 2 NaN NaN 10-Oct-2023 3 4 8 11-Oct-2023 NaN 5 9 12-Oct-2023 NaN 6 10 13-Oct-2023 NaN 7 11
You can refer to the similar community questions for your reference.
You can refer to the below documentation to understand more about "synchronize" function in MATLAB.

Plus de réponses (1)

Nina Sweeney
Nina Sweeney le 9 Oct 2023
I was losing almost half my records when using synchronize. I used outerjoin instead with the "MergeKeys" qualifier and this fixed the issue.

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by