This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


String handling


S = 'Any Characters'
S = [S1 S2 ...]
C = {S1 S2 ...}
S = strcat(S1, S2, ...)
S = char(S1, S2, ...)
S = char(X)
X = double(S)


S = 'Any Characters' creates a character array. The array is actually a vector that contains the numeric codes for the characters (codes from 0 to 65536 are Unicode®, with codes from 0 to 127 also corresponding to 7–bit ASCII). The length of S is the number of characters. A quotation within the character vector is indicated by two quotation marks.

S = [S1 S2 ...] concatenates character arrays S1, S2, etc. into a new character array, S.

C = {S1 S2 ...} creates a cell array of character vectors. Separate each row of the cell array with a semicolon (;).

S = strcat(S1, S2, ...) horizontally concatenates S1, S2, etc., which can be character arrays or cell arrays of character vectors. If the inputs are character arrays, strcat removes trailing white space. For more information, see the strcat reference page.

S = char(S1, S2, ...) vertically concatenates character arrays S1, S2, etc., padding each input array as needed so that each row contains the same number of characters.

S = char(X) converts an array that contains positive integers representing numeric codes into a MATLAB® character array.

X = double(S) converts the character array to its equivalent integer numeric codes.


Create a character vector that includes a single quote.

msg = 'You''re right!'

msg =
You're right!

Create the character vector name using two methods of concatenation.

name = ['Thomas' ' R. ' 'Lee']
name = strcat('Thomas',' R.',' Lee')

Create a character array.

C = char('Hello','Goodbye','Yes','No')

C =

Create a cell array of character vectors.

S = {'Hello' 'Goodbye'; 'Yes' 'No'}

S = 
    'Hello'    'Goodbye'
    'Yes'      'No'

More About

collapse all


  • To convert between character arrays and cell arrays of character vectors, use char and cellstr. Most functions for manipulating text support both types.

  • To determine whether S is a character array or cell array, call ischar(S) or iscellstr(S).

Was this topic helpful?