how to split character data in string and double?

조회 수: 6 (최근 30일)
Bou
Bou 2014년 2월 28일
댓글: Bou 2014년 2월 28일
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

채택된 답변

Andrei Bobrov
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')
  댓글 수: 4
Bou
Bou 2014년 2월 28일
Sorry,
The data is stored in a structure consisting of a several 69x1 cell arrays.
To refer to the second time value I type in;
solar.time(2,1)
Bou
Bou 2014년 2월 28일
I figured it out! Thanks again!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 2월 28일
편집: Azzi Abdelmalek 2014년 2월 28일
str='Time 12:57:33'
out=regexp(str,'\d+(\.)?(\d+)?','match')
  댓글 수: 1
Azzi Abdelmalek
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 CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by