Matlab连接字符串的方法
2012-11-08 18:21
225 查看
http://blog.sina.com.cn/s/blog_7cc248520100svxr.html
在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。
在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。
相关文章推荐
- matlab中字符串连接的3种方法
- 在Matlab中,想要将两个字符串连接在一起,有以下的方法: 假定有两个字符串 >> str1='Iloveyou';str2='123'; 方法一:用中括号将str1和str2像矩阵元素一样包含起来
- Matlab连接字符串的方法
- Matlab连接字符串的方法 八尺戟的空间_百度空间
- Matlab定义字符串数组和连接字符串的方法
- [转]Matlab连接字符串的方法
- Matlab连接字符串的方法
- 【Matlab】连接字符串的方法
- Matlab连接字符串的方法
- ASP.NET web.config中数据库连接字符串connectionStrings节的配置方法
- C#字符串数组的连接方法
- Office 2013/Access 2013 连接字符串/connstr/connection string 解决方法/办法
- JavaScript字符串对象的concat方法实例(用于连接两个或多个字符串)
- Oracle多行记录合并 连接/聚合字符串的几种方法
- SQL Server2005杂谈(4):在SQL Server2005中按列连接字符串的三种方法
- 数据库连接字符串的处理方法!加密解密连接字符串。
- Linux shell脚本中字符串连接的方法
- Python实现string字符串连接的方法总结【8种方式】
- NSString字符串相加连接的三种方法
- axure 中显示日期的字符串连接方法