MATLAB快速入门-文字和字符

当您处理文本时,将字符序列括在单引号中。可以将文本赋给变量。

myText ='Hello, world';

如果文本包含单引号,请在定义中使用两个单引号。

otherText ='You''re right'

otherText =

'You're right'

与所有 MATLAB® 变量一样,myText 和 otherText 为数组。其或数据类型为 char(character 的缩略形式)。

whosmyText

  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'
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。