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.

Text and Characters

When you are working with text, enclose sequences of characters in single quotes. You can assign text to a variable.

myText = 'Hello, world';

If the text includes a single quote, use two single quotes within the definition.

otherText = 'You''re right'
otherText = 
'You're right'

myText and otherText are arrays, like all MATLAB® variables. Their class or data type is char, which is short for character.

whos myText
  Name        Size            Bytes  Class    Attributes

  myText      1x12               24  char               

You can concatenate character arrays with square brackets, just as you concatenate numeric arrays.

longText = [myText,' - ',otherText]
longText = 
'Hello, world - You're right'

To convert numeric values to characters, use functions, such as num2str or int2str.

f = 71;
c = (f-32)/1.8;
tempText = ['Temperature is ',num2str(c),'C']
tempText = 
'Temperature is 21.6667C'