how to get the number from a string in matlab
I want to how know to开发者_开发百科 get certain numbers from a string in matlab. For example, I have a string:
'ABCD_01 36_00 3 .txt', (there is spacing between 01 and 36)
What I need is to get the number 36 and 3. How can I do it in matlab? I've tried finding the answer from previous posts but can not find one that fits this purpose. Thanks for the help.
Regular expressions:
>> str = 'ABCD_01 36_00 3 .txt';
>> t = str2double( regexp(str,'.* (\d+)_.* (\d+)','tokens','once') )
t =
36 3
If the filenames always start with four characters you can do:
>> filename = 'ABCD_01 36_00 3 .txt'; >> sscanf(filename, '%*4c_%*u %u_%*u %u.txt') ans = 36 3
精彩评论