how to split character data in string and double?
3 次查看(过去 30 天)
显示 更早的评论
Hello,
I'm having difficulties separating character arrays. I want to split the char strings below and retrieve the numeric values.
'Time 12:57:33'
'Temp. T2 [deg.C] = 36.6'
'Solar Irradiance [kW/m^2] 0.857101'
Can anybody help me? Im new to Matlab and I know this should be an easy task, but im having quite some trouble with it.
Thanks in advance, greetings Boudewijn
0 个评论
采纳的回答
Andrei Bobrov
2014-2-28
编辑:Andrei Bobrov
2014-2-28
c = {'Time 12:57:33'
'Temp. T2 [deg.C] = 36.6'
'Solar Irradiance [kW/m^2] 0.857101'}
regexp(c,'(\d*:)*\d*(\.\d*)*$','match')
更多回答(1 个)
Azzi Abdelmalek
2014-2-28
编辑:Azzi Abdelmalek
2014-2-28
str='Time 12:57:33'
out=regexp(str,'\d+(\.)?(\d+)?','match')
1 个评论
Azzi Abdelmalek
2014-2-28
编辑:Azzi Abdelmalek
2014-2-28
If your data are stored like:
v={'Time 12:57:33','Temp. T2 [deg.C] = 36.6','Solar Irradiance [kW/m^2] 0.857101';'Time 12:57:33' ,'Temp. T2 [deg.C] = 36.6','Solar Irradiance [kW/m^2] 0.857101'}
out=regexp(v,'[\d:]+(\.)?(\d+)?$','match')
out=[ [out{:,1}]' [out{:,2}]' [out{:,3}]']
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!