南寻 发表于 2018-6-26 11:27:32

MATLAB文本和字符使用方法

当您处理文本时,将字符序列括在单引号中。可以将文本赋给变量。
myText = 'Hello, world';
如果文本包含单引号,请在定义中使用两个单引号。
otherText = 'You''re right'otherText =
'You're right'

与所有 MATLAB 变量一样,myText 和 otherText 为数组。其类或数据类型为 char(character 的缩略形式)。
whos myTextName      Size            BytesClass    Attributes
myText      1x12         24char               

您可以使用方括号串联字符数组,就像串联数值数组一样。
longText = 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'
页: [1]
查看完整版本: MATLAB文本和字符使用方法