Is there an example for reading a text data file with multiple delimiters in MATLAB?
1 次查看(过去 30 天)
显示 更早的评论
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]}
采纳的回答
MathWorks Support Team
2009-6-27
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!