Matlab连接字符串的方法 八尺戟的空间_百度空间
2012-07-12 15:03
375 查看
在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。
假定有两个字符串
>> 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。
相关文章推荐
- 【Matlab】连接字符串的方法
- Matlab定义字符串数组和连接字符串的方法
- 在Matlab中,想要将两个字符串连接在一起,有以下的方法: 假定有两个字符串 >> str1='Iloveyou';str2='123'; 方法一:用中括号将str1和str2像矩阵元素一样包含起来
- Matlab连接字符串的方法
- Matlab连接字符串的方法
- Matlab连接字符串的方法
- Matlab连接字符串的方法
- matlab中字符串连接的3种方法
- [转]Matlab连接字符串的方法
- 不同的数据库有不同的连接字符串(2个方法)
- Oracle字符串连接的方法
- 如果想对web.config的数据库连接字符串进行加密的话,这里提供了两个方法:
- 连接加密Access数据库的字符串设置方法
- Python字符串类型(创建、索引、切片、成员操作符、重复、连接、计算长度、内置方法)
- MSSQL Server数据库的四种连接方法和sql连接字符串
- js 将用连接符连接的英文字符串转换成驼峰命名的三种方法
- 【oracle】Oracle中字符串连接的实现方法【转】
- Oracle多行记录合并/连接/聚合字符串的几种方法
- Oracle多行记录合并 连接/聚合字符串的几种方法
- matlab中text 函数在显示字符串时的使用方法