How do I combine data from seperate tables into one table with seperate columns

I am trying to combine data from several tables into 1 table. The data is 10-minute data from turbines. So every day has 144 entries. Some turbines have days missing and therefore their length is shorter. The data looks like the following
T1
Column1 Column2 Column3
Date Time Output
01/01/2014 00:10:00 68
01/01/2014 00:20:00 68
01/01/2014 00:30:00 68
: : :
: : :
: : :
01/01/2014 23:40:00 68
01/01/2014 23:50:00 68
02/01/2014 00:00:00 68
T2
Column1 Column2 Column3
Date Time Output
01/01/2014 00:10:00 68
01/01/2014 00:20:00 68
01/01/2014 00:30:00 68
: : :
: : :
: : :
01/01/2014 23:40:00 68
01/01/2014 23:50:00 68
00/01/2014 00:00:00 68
Desired

 Réponse acceptée

Assuming all tables have the same number of columns with matching Variable Names, you can vertically concatenate them like this.
T = [T1; T2; T3];

7 commentaires

there are some dates missing, this is the main part of my issue
If you're vertically concatenating them, it doesn't matter how many rows each matrix has. Do you want to horizontally concatenat them instead? Or do you want to just have 1 column of dates, 1 column of times, and n columns of Output from n tables?
Output should look like this:
Tout
Column1 Column2 Column3 Column 4 ----- Column N
Date Time Output T1 Output T2 ---- Output TN
01/01/2014 00:10:00 68 34 43
02/01/2014 00:20:00 68 NA 43
03/01/2014 00:30:00 NA 34 43
Adam Danz
Adam Danz le 5 Fév 2020
Modifié(e) : Adam Danz le 5 Fév 2020
That's much more descriptive. Here's the steps you'll need to take.
  1. For each table, use the column1 (dates) and column 2( times) to create a single datetime value for each row and add that column vector to the table. You can remove the Date and Time columns after that.
  2. As Steven Lord suggested, convert them to timetables and specify the new datetime columns as the "RowTimes". TT = table2timetable(T,'RowTimes',timeVarName) (see the link). It would probably be easiest if you put all of the tables into a cell array and just loop through the array.
  3. Then use TT = synchronize(TT1,...,TTN,___) to combine the tables as you described above. Again, if the tables are all stored in a cell array, it would be as easy as synchronize(CellArray{:}).
If you run into any snags, I'd be glad to make further recommendations.
How would I do step 1?
What format are those columns in? Are the dates already datetime values? Is the time column durations or are they also datetime values (or something else)? If you're unsure,
class(T.Date) % where T is your table name
class(T.Time)
Here's the datetime documentation
I see that you continued the conversation here. Once that's worked out you can continue with step 2 and let us know if you get stuck.

Connectez-vous pour commenter.

Plus de réponses (1)

Consider converting these table arrays into timetable arrays. If you do you can synchronize them all to a common time basis. See this documentation page for several examples of how to synchronize timetable arrays.

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by