matlab中字符串连接的方法

本文介绍了MATLAB中四种字符串连接方法:直接串联、strcat函数、sprintf函数和join函数。特别是sprintf函数,它能将字符串与数值数据混合拼接成字符串。
摘要由CSDN通过智能技术生成

matlab中字符串连接的方法

N个字符串 串联连接在一起并输出


***第一种方法 [ ]字符串数组***

```matlab
str1='test_img';
str2='.png';
%test_img.png 是当前目录下的测试图片
file_name=[str1,str2];
im=imread(file_name);
imshow(im);

%output : file_name='test_img.png'

第二种方法 strcat( ) 水平串联字符串

str1='I';
str2=' love';
str3=' you';
str4='!';
str = strcat(str1,str2,str3,str4);

%output: str=I love you!

%s = strcat(s1,...,sN) 水平串联 s1,...,sN。每个输入参数都可以是字符数组、字符向量元胞数组或字符串数组
%for example

% 1、字符数组
%该种方式是组合使用了字符串数组和strcat两种方式来拼接字符串。首先使用字符数拼接数组内的字符串,再将字符数据拼接后的字符串最为参数传递给strcat进行第二次拼接。
str = strcat(['hello' ' world,'],[' hello' ' Matlab!']);
% output: str = hello world, hello Matlab!

% 2、字符串数组
str = strcat(["
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值