當(dāng)您處理文本時岛心,將字符序列括在單引號中来破。可以將文本賦給變量忘古。
myText ='Hello, world';
如果文本包含單引號徘禁,請在定義中使用兩個單引號。
otherText ='You''re right'
otherText =
'You're right'
與所有 MATLAB? 變量一樣髓堪,myText 和 otherText 為數(shù)組送朱。其類或數(shù)據(jù)類型為 char(character 的縮略形式)。
whosmyText
Name Size Bytes Class Attributes
myText 1x12 24 char
您可以使用方括號串聯(lián)字符數(shù)組干旁,就像串聯(lián)數(shù)值數(shù)組一樣驶沼。
longText = [myText,' - ',otherText]
longText =
'Hello, world - You're right'
要將數(shù)值轉(zhuǎn)換為字符,請使用 num2str 或 int2str 等函數(shù)争群。
f = 71;c = (f-32)/1.8;
tempText = ['Temperature is ',num2str(c),'C']
tempText =
'Temperature is 21.6667C'