字符串轉換函數
abs 字符串到ASCII轉換
dec2hex 十進制數到十六進制字符串轉換
fprintf 把格式化的文本寫到文件中或顯示屏上
hex2dec 十六進制字符串轉換成十進制數
hex2num 十六進制字符串轉換成IEEE浮點數
int2str 整數轉換成字符串
lower 字符串轉換成小寫
num2str 數字轉換成字符串
setstr ASCII轉換成字符串
sprintf 用格式控制,數字轉換成字符串
sscanf 用格式控制,字符串轉換成數字
str2mat 字符串轉換成一個文本矩陣
str2num 字符串轉換成數字
upper 字符串轉換成大寫
matlab字符串拼接
假定有兩個字符串
>> str1='Iloveyou';str2='123';
方法一:用中括號將str1和str2像矩陣元素一樣包含起來:
>> SC=[str1,str2]
SC =
Iloveyou123
(若想驗證str1和str2確實被連接起來,可調用length函數測試SC的長度。)
方法二:用strcat函數
>> SB=strcat(str1,str2)
SB =
Iloveyou123
注意,strcat函數有許多用法,如下例:
>> strcat({'Red','Yellow'},{'Green','Blue'})
ans =
'RedGreen' 'YellowBlue'
但下句則結果就不一樣了:
>> strcat(['Red','Yellow'],['Green','Blue'])
ans =
RedYellowGreenBlue
方法三:利用sprintf函數
>> number=123;
>> STR=sprintf('%s%d',str1,number)
STR =
Iloveyou123
利用class(STR)得到STR的類型為char。