how to concatenate two tables into one such that the timestamps of two tables are in sequence and the corresponding values are arranged according to their timestamps

3 views (last 30 days)
i have two tables with engine data such that in the first table the first column contains timestamp and second column contains speed data, in the second table the first column is a timestamp and the second column is gear data. i want to make these two tables to one such that the first column contains timestamps of both tables arranged in a sequence and then the second and third column contains their corresponding speed and gear values respectively.
i used code such as t = [t1 t2];
but this does not arrange them in a sequence.
also i dont know how to write the speed and gear values corresponding to their timestamps.
can someone help me with this problem please
  1 Comment
J. Alex Lee
J. Alex Lee on 5 Mar 2020
when you say "table" do you mean, in terms of matlab data types, an actual table? or are you actually using matlab arrays?
class(t1)
class(t2)
Are your timestamps the same in both sets of data such that you have both gear and speed data at the same times? If this is not the case, what do you expect to fill in the missing data?

Sign in to comment.

Answers (1)

Guillaume
Guillaume on 5 Mar 2020
It should be very easy. Convert your tables to timetables (if they're not already) then call synchronize:
speedtimetable = table2timetable(yourspeedtable);
geartimetable = table2timetable(yourgeartable);
speedandgear = synchronize(speedtimetable, geartimetable);
in theory. If this doesn't work then attach a mat file with your two tables.
  1 Comment
amir-nejati
amir-nejati on 22 Apr 2023
The only issue with this solution is when in one of your table or timetable there are some rows with the same timestamp, in that case the synchronize function will ignore one of the rows,any idea how to solve that problem?
Thanks

Sign in to comment.

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!