strcat

Joins text horizontally.

Category: Language Fundamentals > Data Types

Syntax

s = strcat(s1, s2, ...)

Concatenates the inputs, element by element for arrays and cells.

Description

For character inputs, strcat removes trailing whitespace from each argument before joining, so strcat('ab ', 'cd') is 'abcd'. For string and cell inputs, whitespace is kept as given. To keep trailing blanks in character data, use [s1 s2] or append.

With a cell array and a scalar text, the text is appended to every cell, which is a quick way to add a suffix to a list of names.

Input arguments

s1, s2, ...
Character vectors, strings, or cell arrays of character vectors. Cell arrays must have the same size, or be scalar.

Output arguments

s
Character vector if all inputs are character vectors, string if any input is a string, or a cell array if any input is a cell.

Example

Characters, cells and strings

strcat('ab ', 'cd')
strcat({'a ', 'b'}, 'x')
["ab " + "cd"]
Output
ans = 'abcd'
ans = 1×2 cell

    {'a x'}    {'bx'}
ans = "ab cd"

See also

append plus horzcat join strjoin