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

16 次查看(过去 30 天)
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 个评论
J. Alex Lee
J. Alex Lee 2020-3-5
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?

请先登录,再进行评论。

回答(1 个)

Guillaume
Guillaume 2020-3-5
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 个评论
amir-nejati
amir-nejati 2023-4-22
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by