Is there an example for reading a text data file with multiple delimiters in MATLAB?
1 view (last 30 days)
Show older comments
I would like to use TEXTSCAN to read an ASCII file that contains time series data in the following format:
07-01-2003 14:00:00, 0.00614, 0.01986, 0.00000, 0.20094, 0.05174, -0.03086, -0.29720, 0.00000
07-01-2003 14:00:01, 0.00920, 0.01976, 0.00000, 0.20104, 0.05164, -0.03086, -0.29720, 0.00000
I would like to treat the date and time as columns, e.g. one column for day, one for month, one for year etc. How can I use TEXTSCAN's input arguments (scan format, extra arguments) to get this as a result:
{[7;7]} {[1;1]} {[2003;2003]} {[14;14]} {[0;0]} {[0;1]} {[ 0.00614; 0.00920]}
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
This can be done using a combination of both TEXTSCAN to read in the data, and the REGEXPI function to use regular expressions to organize the data. For example:
txt = textread('text.txt', '%s', 'delimiter', '\n');
m = regexpi(txt,'(?:[0-9]\.[0-9]*|[0-9]*)', 'match')
For more information on the REGEXPI function, execute the following at the MATLAB command prompt:
doc regexpi
0 Comments
More Answers (0)
See Also
Categories
Find more on Text Files in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!