read pre-formated text file

1 view (last 30 days)
majid
majid on 1 Oct 2014
Edited: majid on 1 Oct 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 .

Accepted Answer

dpb
dpb on 1 Oct 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 Comment
majid
majid on 1 Oct 2014
Edited: majid on 1 Oct 2014
i don't know what to say . thats perfect . you're too kind . thanks again.

Sign in to comment.

More Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!