|
当您处理文本时,将字符序列括在单引号中。可以将文本赋给变量。
如果文本包含单引号,请在定义中使用两个单引号。
- otherText = 'You''re right'
复制代码 otherText =
'You're right'
与所有 MATLAB 变量一样,myText 和 otherText 为数组。其类或数据类型为 char(character 的缩略形式)。
Name Size Bytes Class Attributes
myText 1x12 24 char
您可以使用方括号串联字符数组,就像串联数值数组一样。
- longText = [myText,' - ',otherText]
复制代码 longText =
'Hello, world - You're right'
要将数值转换为字符,请使用 num2str 或 int2str 等函数。
- f = 71;
- c = (f-32)/1.8;
- tempText = ['Temperature is ',num2str(c),'C']
复制代码 tempText =
'Temperature is 21.6667C'
|
|