matlab字符串数组转数值数组
1.---------------------------------------------------------------------------
>> Cab_group =randperm(80,4);%⼀次随机产⽣4个不同叶绿素含量给4株植物,最⾼是80
rand_group =round(rand(1,4),2);
Cab_group =string(Cab_group + rand_group)
Cab_group =
1×4 string 数组
"47.29""55.72""45.79""32.88"
>>  Cab_group =str2num(Cab_group)
错误使⽤str2num(line 31)
需要字符⽮量或数组输⼊。
>> Cab_group =str2double(Cab_group)
Cab_group =
47.290055.720045.790032.8800
⽤str2double替换掉str2num
2.-------------------------------------------------------------------------------------
>> wavelength =400:35:1500
wavelength =
1⾄13列
400435470505540575610645680715750785820
14⾄26列
85589092596099510301065110011351170120512401275
27⾄32列
131013451380141514501485
>>num2str(wavelength)
ans =
4004354705055405756106456807157507858208558909259609951030106511001135117012051240127513 1013451380141514501485
>> wavelength =cellstr(wavelength)
错误使⽤cellstr(line 45)
输⼊必须为字符⽮量。
>> wavelength =cellstr(num2str(wavelength))
wavelength =
cell
'400  435  470  505  540  575  610  645  680  715  750  785  820  855  890  925  960  995  1030  1065  1100  1135  1170  1205  1240  12…'
>>
3.将数值数组转为元组,元组内单个元素为char型,单引号,作为出图的时候legend的参数输⼊。
>> wavelength =400:35:1500
wavelength =matlab数组赋值
1⾄13列
400435470505540575610645680715750785820
14⾄26列
85589092596099510301065110011351170120512401275 27⾄32列
131013451380141514501485
>>    new_wavelength =cell(1,32);
for wa=1:length(wavelength)
new_wavelength(1,wa)={num2str(wavelength(wa))};
end
>> new_wavelength
new_wavelength =
1×32 cell 数组
1⾄17列
'400''435''470''505''540''575''610''645''680''715''750''785''820''855''890''925''960'
18⾄32列
'995''1030''1065''1100''1135''1170''1205''1240''1275''1310''1345''1380''1415''1450''1485' >>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。