read pre-formated text file

3 Ansichten (letzte 30 Tage)
majid
majid am 1 Okt. 2014
Bearbeitet: majid am 1 Okt. 2014
hello dears . i must read a text file such this :
person01_boxing_d1 frames 1-95, 96-185, 186-245, 246-360
person01_boxing_d2 frames 1-106, 107-195, 196-265, 305-390
person01_boxing_d3 frames 1-95, 96-230, 231-360, 361-465
person01_boxing_d4 frames 1-106, 107-170, 171-245, 246-370
person01_handclapping_d1 frames 1-102, 103-182, 183-260, 261-378
person01_handclapping_d2 frames 1-162, 163-282, 358-472, 473-550
person01_handclapping_d3 frames 1-125, 126-225, 226-330, 331-428
person01_handclapping_d4 frames 1-110, 111-216, 217-292, 293-390
------------------------------------- i need this information
person 01 _ boxing _d 1 frames 1 - 95 , 96 - 185 , 186 - 245 , 246 - 360
i.e :
01 boxing 1 1 95 96 185 186 245 246 360
i can not read all information because action types (e.g boxing , handclapping , ..) have different length . please help me . thank you for your time .

Akzeptierte Antwort

dpb
dpb am 1 Okt. 2014
>> s='person01_boxing_d1 frames 1-95, 96-185, 186-245, 246-360';
>> fmt=['person%2d%sd%d frames ' repmat('%d-%d',1,4)];
>> a=textscan(s,fmt,'collectoutput',1,'delimiter','_,')
a =
[1] {1x1 cell} [1x9 int32]
>> a{:}
ans =
1
ans =
'boxing'
ans =
1 1 95 96 185 186 245 246 360
>> s='person01_handclapping_d2 frames 1-162, 163-282, 358-472, 473-550';
>> b=textscan(s,fmt,'collectoutput',1,'delimiter','_,')
b =
[1] {1x1 cell} [1x9 int32]
>> b{:}
ans =
1
ans =
'handclapping'
ans =
2 1 162 163 282 358 472 473 550
>>
  1 Kommentar
majid
majid am 1 Okt. 2014
Bearbeitet: majid am 1 Okt. 2014
i don't know what to say . thats perfect . you're too kind . thanks again.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Text Data Preparation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by