Matlab连接字符串的方法
2013-01-31 15:45
495 查看
转自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连接字符串的方法
- Matlab连接字符串的方法
- 【Matlab】连接字符串的方法
- matlab中字符串连接的3种方法
- Matlab连接字符串的方法
- 在Matlab中,想要将两个字符串连接在一起,有以下的方法: 假定有两个字符串 >> str1='Iloveyou';str2='123'; 方法一:用中括号将str1和str2像矩阵元素一样包含起来
- Matlab连接字符串的方法
- Matlab连接字符串的方法 八尺戟的空间_百度空间
- Matlab定义字符串数组和连接字符串的方法
- 输入两个字符串,比如abdbcc和abc,输出第二个字符串在第一个字符串中的连接次序(递归方法)
- 细说C#中连接字符串的方法“+”和Append
- js脚本三种实现字符串连接方法
- web.config 保存(Access)数据库连接字符串的两种方法
- JavaScript实现将数组中所有元素连接成一个字符串的方法
- ASP.NET web.config中数据库连接字符串connectionStrings节的配置方法
- Oracle字符串连接的使用方法
- python字符串连接方法
- 为web.config写入数据库连接字符串的方法
- asp.net2.0中读取web.config数据库连接字符串2种方法
- 在软件中使用“连接字符串(ConnectionString)生成向导对话框”方法大全