Products & Services Industries Academia Support User Community Company

Learn more about MATLAB   

strcat - Concatenate strings horizontally

Syntax

t = strcat(s1, s2, s3, ...)

Description

t = strcat(s1, s2, s3, ...) horizontally concatenates corresponding rows of the character arrays s1, s2, s3, etc. All input arrays must have the same number of rows (or any can be a single string). When the inputs are all character arrays, the output is also a character array.

When any of the inputs is a cell array of strings, strcat returns a cell array of strings formed by concatenating corresponding elements of s1, s2, etc. The inputs must all have the same size (or any can be a scalar). Any of the inputs can also be character arrays.

strcat ignores trailing ASCII white space characters and omits all such characters from the output. White space characters in ASCII are space, newline, carriage return, tab, vertical tab, or form-feed characters, all of which return a true response from the MATLAB isspace function. Use the concatenation syntax [s1 s2 s3 ...] to preserve trailing spaces. strcat does not ignore inputs that are cell arrays of strings.

Remarks

strcat and matrix operation are different for strings that contain trailing spaces:

a = 'hello '
b = 'goodbye'
strcat(a, b)
ans =
hellogoodbye
[a b]
ans =
hello goodbye

Examples

Given two 1-by-2 cell arrays a and b,

a = 							b = 
    'abcde'    'fghi'							 	'jkl'    'mn'

the command t = strcat(a,b) yields

t = 
    'abcdejkl'    'fghimn'

Given the 1-by-1 cell array c = {`Q'}, the command t = strcat(a,b,c) yields

t = 
    'abcdejklQ'    'fghimnQ'

See Also

strvcat, cat, vertcat, horzcat, cellstr, special character []

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS