Combine Tables with different record rate

4 vues (au cours des 30 derniers jours)
Richard Vergin
Richard Vergin le 22 Juil 2018
Commenté : Richard Vergin le 13 Oct 2018
Hey Everybody,
I need to join two tables by the common Parameter "Time_secs_" which represents the record date of my sensor data. Unfortunately, in one table the record is 0.5 seconds while in the second it is 0.1 seconds. Therefore the second table has 481002 rows while the first only has 80167 rows.
Now I want to join them by their record rate and simply add blank cells for every signal from table 1 to the time_secs_0 0.1, 0.2, 0.25, 0.3, 0.4, 0.6, 0.7, 0.75, 0.8, 0.9 (some signals are also taken every 0.25 seconds, thats why 0.25 and 0.75 are included).
How can I do this? Is there any specification I can make to the "join"-function or will it not work with this at all?
Thanks a lot in advance!
  6 commentaires
Richard Vergin
Richard Vergin le 24 Juil 2018
For interested readers: after adding a Time-Column with similar values (thanks to Guillaume's solution) I was able to combine the tables. Outerjoin works for adapting the fine record rate, joing for adapting the small one.
Peter Perkins
Peter Perkins le 3 Août 2018
Richard, you can do that (use tables and joins), but if you are using R2016b or later, you will be much happier using timetables and synchronize:
>> tt1 = timetable((1:10)','RowTimes',seconds(0:1:9))
tt1 =
10×1 timetable
Time Var1
_____ ____
0 sec 1
1 sec 2
2 sec 3
3 sec 4
4 sec 5
5 sec 6
6 sec 7
7 sec 8
8 sec 9
9 sec 10
>> tt2 = timetable((11:15)','RowTimes',seconds(0:2:8))
tt2 =
5×1 timetable
Time Var1
_____ ____
0 sec 11
2 sec 12
4 sec 13
6 sec 14
8 sec 15
>> synchronize(tt1,tt2)
ans =
10×2 timetable
Time Var1_tt1 Var1_tt2
_____ ________ ________
0 sec 1 11
1 sec 2 NaN
2 sec 3 12
3 sec 4 NaN
4 sec 5 13
5 sec 6 NaN
6 sec 7 14
7 sec 8 NaN
8 sec 9 15
9 sec 10 NaN
But beware: .1 is not a nice floating point number. You may find that synchronize treats some times that look the same as different, because they are different. At that level of resolution, you are usually better off using the milliseconds function to construct time vectors than using the seconds function.

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
Guillaume le 24 Juil 2018
How can I create an additional column within the table which contains all the information of those three others and makes a time out of this?
yourtable.newcolumnname = datetime([zeros(height(yourtable), 3), yourtable.hourcolumn, yourtable.minutecolumn, yourtable.secondcolumn], 'Format', 'HH:mm:ss')
  5 commentaires
Walter Roberson
Walter Roberson le 13 Oct 2018
What is the
zeros(height(Minus22_FlightParameter_Hydraulics_Uniform_Table),6),
part there for? That is going to generate 6 columns of zeros, and then you add on 6 more columns of numeric values, for a total of 12 columns.
Richard Vergin
Richard Vergin le 13 Oct 2018
Ah I don’t Know I just reused that code line. But without it works perfectly fine, thanks a lot! :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by