String 将字符串拆分为不同的位
我有一个字符串,看起来像这样: 子字符串='Xmole1=0.0Xmole2=1.0rho1=2343rho2=2343' 我需要将其分为:String 将字符串拆分为不同的位,string,matlab,String,Matlab,我有一个字符串,看起来像这样: 子字符串='Xmole1=0.0Xmole2=1.0rho1=2343rho2=2343' 我需要将其分为: Xmole(1)=0.0 Xmole(2)=1.0 rho(1)=2343 rho(2)=2343 有没有更简单的方
Xmole(1)=0.0
Xmole(2)=1.0
rho(1)=2343
rho(2)=2343
有没有更简单的方法 如果您的数字始终采用示例的格式,即数字和小数点,而不是1.0e-3格式:
ind = regexp(substring,'=[\d\.]+', 'end');
result = mat2cell(substring, 1, [ind(1) diff(ind)]).';
变量结果是一个单元格数组,每个单元格中有一个字符串:
result =
'Xmole(1)=0.0'
'Xmole(2)=1.0'
'rho(1)=2343'
'rho(2)=2343'
字符串最初是从哪里来的?如果以某种方式对其进行分隔,会容易得多。你能改变这个字符串的创建方式吗?