how to split character data in string and double?

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 日

0 投票

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 日
Thank you!
This is exactly what I want my output to look like! However I want to generate columns of time values, columns of temp values, etc.
I actually have a structure with a column of time values, a column of irradiance values etc.
How can I adjust the code to retrieve it seperately?
'Time 12:57:33'
'Time 12:57:51'
'Time 12:58:37'
And to refer to the first time value I type in
'solar.time(1,1)'
Thanks in advance!
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 2 月 28 日
You didn't explain how your data are stored, post a sample of your data for at least two time values
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 日

0 投票

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}]']

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeSolar Power についてさらに検索

質問済み:

Bou
2014 年 2 月 28 日

コメント済み:

Bou
2014 年 2 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by