Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Combine strings, or merge two tables or timetables by rows using key variables

`newStr = join(str)`

`newStr = join(str,delimiter)`

`newStr = join(str,dim)`

`newStr = join(str,delimiter,dim)`

`tblC = join(tblA,tblB)`

`tblC = join(tblA,tblB,Name,Value)`

```
[tblC,ib]
= join(___)
```

concatenates
the text in the input array `newStr`

= join(`str`

)`str`

, placing a space
character between consecutive elements, and returns the result as `newStr`

.
The input array `str`

can be a string array or a
cell array of character vectors. `newStr`

has the
same data type as `str`

.

If

`str`

is a`1`

-by-`N`

or an`N`

-by-`1`

string array or cell array, then`newStr`

is a string scalar or a cell array that contains one character vector.If

`str`

is an`M`

-by-`N`

string array, then`newStr`

is an`M`

-by-`1`

string array or cell array.

For a string or cell array of any size, `join`

concatenates
elements along the last dimension of `str`

with a
size that does not equal `1`

.

combines
the text in `newStr`

= join(`str`

,`delimiter`

)`str`

and places the elements of `delimiter`

between
the elements of `str`

instead of a space character.

If the `delimiter`

argument is an array of
different delimiters, and `str`

has `N`

elements
along the dimension that is joined, then `delimiter`

must
have `N-1`

elements along the same dimension. The
other dimensions of `delimiter`

must have either
a size of `1`

or the same size as the corresponding
dimension of `str`

.

merges `tblC`

= join(`tblA,tblB`

)`tblA`

and `tblB`

by
matching up rows, using all the variables with the same names as key variables. The key values must be common
to both `tblA`

and `tblB`

, but can
appear in different orders. `tblA`

and `tblB`

can
be both tables, both timetables, or one of each.

If

`tblA`

is a table, then`join`

returns`tblC`

as a table.If

`tblA`

is a timetable, then`join`

returns`tblC`

as a timetable.

`join`

retains all the variables from `tblA`

and
appends the corresponding contents from the nonkey variables of `tblB`

.

The row labels of `tblA`

and `tblB`

can
be key variables. Row labels are the row names of a table, or the
row times of a timetable.

joins
the tables or timetables with additional options specified by one
or more `tblC`

= join(`tblA,tblB`

,`Name,Value`

)`Name,Value`

pair arguments.

For example, you can specify which variables to use as key variables.

The `join`

function first finds one or more
key variables. Then, `join`

uses the key variables
to find the row in input table `tblB`

that matches
each row in input table `tblA`

, and combines those
rows to create a row in output table `tblC`

.

If there is a one-to-one mapping between key values in

`tblA`

and`tblB`

, then`join`

sorts the data in`tblB`

and appends it to table`tblA`

.If there is a many-to-one mapping between key values in

`tblA`

and`tblB`

, then`join`

sorts and repeats the data in`tblB`

before appending it to table`tblA`

.If there is data in a key variable of

`tblB`

that does not map to a key value in`tblA`

, then`join`

does not include that data in the output table,`tblC`

.

Was this topic helpful?