Main Content

joindata

Merge two frame tables using an outer join

Since R2020a

Description

joindata is a function used in code generated by Diagnostic Feature Designer.

table12 = joindata(table1,table2) merges two tables using an outer join with the first two columns as the primary keys to merge. In general, an outer join combines table rows where the key variables have matching values, while also retaining rows where key variables from one input table have no matches in the other input table (see outerjoin). joindata joins two frame tables. The first two columns of both frame tables contain the segment start and segment end points. The other columns in the tables contain data associated with the frame. The data column names must be unique, that is, data columns in table2 must not have the same name as the data columns in table1.

Code that is generated by Diagnostic Feature Designer uses joindata when performing frame-based ensemble statistics processing. In the code, table1 contains existing frame data and table2 contains newly computed frame results.

table12 = joindata(table1,table2,'Keys',keys) uses the columns with the names specified in keys as the primary keys for the merge. For example, 'Keys',["TimeStart","TimeEnd"] specifies that joindata use the columns named TimeStart and TimeEnd rather than automatically using the first two columns for primary keys.

example

Examples

collapse all

Merge two overlapping frame tables.

Create table1, a 4-by-3 table that contains values for variable Var1 in four successive 5-second frames.

table1 = table(seconds(0:5:15)', seconds(5:5:20)', [3;4;5;6], ...
    'VariableNames', ["TimeStart", "TimeEnd", "Var1"])
table1=4×3 table
    TimeStart    TimeEnd    Var1
    _________    _______    ____

      0 sec       5 sec      3  
      5 sec      10 sec      4  
     10 sec      15 sec      5  
     15 sec      20 sec      6  

Create table2, also a 4-by-3 table, that overlaps the frames in table1. table2 contains the values for Var2.

table2 = table(seconds(5:5:20)', seconds(10:5:25)', [1;2;3;4], ...
    'VariableNames', ["TimeStart", "TimeEnd", "Var2"])
table2=4×3 table
    TimeStart    TimeEnd    Var2
    _________    _______    ____

      5 sec      10 sec      1  
     10 sec      15 sec      2  
     15 sec      20 sec      3  
     20 sec      25 sec      4  

Merge the two tables using TimeStart and TimeEnd as the merge keys.

table12 = joindata(table1, table2, 'Keys', ["TimeStart", "TimeEnd"])
table12=5×4 table
    TimeStart    TimeEnd    Var1    Var2
    _________    _______    ____    ____

      0 sec       5 sec       3     NaN 
      5 sec      10 sec       4       1 
     10 sec      15 sec       5       2 
     15 sec      20 sec       6       3 
     20 sec      25 sec     NaN       4 

table12 is a 5-by-4 table that contains the values for Var1 and Var2 for each frame. Missing values are represented by NaN.

Input Arguments

collapse all

First frame table to merge, specified as a table with the first two columns representing the segment start and stop points, and the remaining columns containing the corresponding data.

Second frame table to merge, specified as a table with the first two columns representing the segment start and stop point, and the remaining columns containing the corresponding data. Data column names must not match any data column names in table1.

Primary keys for table merge, specified as the comma-separated pair containing 'Keys' and either a string array with two strings or a cell of two character arrays.

Output Arguments

collapse all

Merged frame data, returned as a table.

Version History

Introduced in R2020a