This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Join strings in array


str = strjoin(C)
str = strjoin(C,delimiter)



str = strjoin(C) constructs str by linking the elements of C with a space between consecutive elements. C can be a cell array of character vectors or a string array.


str = strjoin(C,delimiter) constructs str by linking each element of C with the elements in delimiter.


collapse all

Join individual character vectors in a cell array of character vectors, C, with a single space.

C = {'one','two','three'};
str = strjoin(C)
str = 
'one two three'

Join the character vectors in a cell array into one character vector. Specify a comma followed by a space character as the delimiter.

C = {'Newton','Gauss','Euclid','Lagrange'}
C = 1x4 cell array
    {'Newton'}    {'Gauss'}    {'Euclid'}    {'Lagrange'}

str = strjoin(C,', ')
str = 
'Newton, Gauss, Euclid, Lagrange'

Specify multiple different delimiters in a cell array of character vectors. The delimiter cell array must have one fewer element than C.

C = {'one','two','three'};
str = strjoin(C,{' + ',' = '})
str = 
'one + two = three'

Input Arguments

collapse all

Input text, specified as a 1-by-n cell array of character vectors or string array.

Example: {'The','rain','in','Spain'}

Example: string({'Four','score','and','seven'})

Data Types: cell | string

Delimiting characters, specified as a character vector, a 1-by-n cell array of character vectors, or a 1-by-n string array.

  • If delimiter is a character vector, then strjoin forms str by inserting delimiter between each element of C. The delimiter input can include any of these escape sequences:










    Form feed


    New line


    Carriage return


    Horizontal tab


    Vertical tab

  • If delimiter is a cell array of character vectors, then it must contain one fewer element than C. Each element in the cell array must contain a character vector. strjoin forms str by interleaving the elements of delimiter and C. All characters in delimiter are inserted as literal text, and escape sequences are not supported.

Example: ', '

Example: {',',' '}

Data Types: char | cell | string


  • Starting in R2016b, the join function is recommended to join elements of a string array.

Extended Capabilities

Introduced in R2013a