matlab字符串操作

字符串转换函数

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。

原文地址:https://www.cnblogs.com/hujianhua/p/3217218.html