Importing only specific entries from a text file to matlab
4 views (last 30 days)
I am trying to import a text file, but do not need all the information, just only specifics (after the : operator). Here is a sample version of the text file
Select type (A or B or C): C Enter the number of days: 30 Select test type (Reg or Mod): Reg Enter the number of TC's used: 1
The data is a mix of alphanumeric and numeric. So I need something that handle both. Any help will be appreciated. Thanks
Cedric Wannaz on 21 Mar 2013
Edited: Cedric Wannaz on 21 Mar 2013
Regular expressions are probably your best option. Look at the following:
>> s = 'Select type (A or B or C): C Enter the number of days: 30 Select test type (Reg or Mod): Reg Enter the number of TC''s used: 1' ;
>> results = regexp(s, '(?<=:\s+)\S+', 'match')
'C' '30' 'Reg' '1'
The second argument in the call to REGEXP is the pattern. Let me know if you need help to understand it.