how to split character data in string and double?

6 visualizaciones (últimos 30 días)
Bou
Bou el 28 de Feb. de 2014
Comentada: Bou el 28 de Feb. de 2014
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

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 28 de Feb. de 2014
Editada: Andrei Bobrov el 28 de Feb. de 2014
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 comentarios
Bou
Bou el 28 de Feb. de 2014
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 el 28 de Feb. de 2014
I figured it out! Thanks again!

Iniciar sesión para comentar.

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 28 de Feb. de 2014
Editada: Azzi Abdelmalek el 28 de Feb. de 2014
str='Time 12:57:33'
out=regexp(str,'\d+(\.)?(\d+)?','match')
  1 comentario
Azzi Abdelmalek
Azzi Abdelmalek el 28 de Feb. de 2014
Editada: Azzi Abdelmalek el 28 de Feb. de 2014
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}]']

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by