Documentation Center

  • Trial Software
  • Product Updates


Concatenate strings horizontally


  • combinedStr = strcat(s1,s2,...,sN) example



combinedStr = strcat(s1,s2,...,sN) horizontally concatenates strings in arrays. Inputs can be combinations of single strings, strings in scalar cells, character arrays with the same number of rows, and same-sized cell arrays of strings.

  • If any input is a cell array, combinedStr is a cell array of strings. Otherwise, combinedStr is a character array.

  • For character array inputs, strcat removes trailing ASCII white-space characters: space, tab, vertical tab, newline, carriage return, and form-feed. For cell array inputs, strcat does not remove trailing white space.


expand all

Concatenate Two Strings

str = strcat('Good', 'morning')
str =


Concatenate Two Cell Arrays

a = {'abcde', 'fghi'};
b = {'jkl', 'mn'};

ab = strcat(a, b)
ab = 

    'abcdejkl'    'fghimn'

Concatenate Two Cell Arrays with Scalar Cell

a = {'abcde', 'fghi'};
b = {'jkl', 'mn'};
c = {'Q'};

abc = strcat(a, b, c)
abc = 

    'abcdejklQ'    'fghimnQ'

Input Arguments

expand all

s1,s2,...,sN — Strings to horizontally concatenatestring | cell array of strings | character arrays

Strings to horizontally concatenate, specified as strings, cell arrays of strings, or character arrays with the same number of strings. When combining nonscalar cell arrays and multirow character arrays, cell arrays must be column vectors with the same number of rows as the character arrays.

Data Types: char | cell

More About

expand all


  • strcat strips trailing blank spaces. Adding a blank space at the end of the first string does not result in a blank space between the strings once concatenated.

    str1 = strcat('Good ', 'morning')
    str1 =

    Instead, add a blank space before the second string.

    str2 = strcat('Good', ' morning')
    str2 =
    Good morning
  • Strings can be horizontally concatenated using horizontal array concatenation. Horizontal array concatenation does not strip off trailing blank spaces from a string.

    a = 'Good ';
    b = 'Morning';
    using_strcat = strcat(a, b)
    using_arraycat = [a b]    % Equivalent to horzcat(a, b)
    using_strcat =
    using_arraycat =
    Good Morning

See Also

| | | | |

Was this topic helpful?