read pre-formated text file

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 .

 采纳的回答

>> 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 个评论

majid
majid 2014-10-1
编辑:majid 2014-10-1
i don't know what to say . thats perfect . you're too kind . thanks again.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Text Data Preparation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by