文本和字符

    科技2023-10-12  106

    文本和字符

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

    myText = ‘Hello, world’;

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

    otherText = ‘You’‘re right’ otherText = ‘You’re right’

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

    whos myText 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’] tempText = ‘Temperature is 21.6667C’

    Processed: 0.010, SQL: 8