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

조회 수: 11 (최근 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