How to use textscan to read this .dat file?
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I fail to use textscan to read the following formatted data. What should be the correct argument to read it and let the same data type be in a single array? Thanks!
{"time":1431653957, "OD":0.0010, "Z":0.0000, "U":0}
{"time":1431654017, "OD":0.0007, "Z":0.0000, "U":0}
{"time":1431654077, "OD":-0.0005, "Z":0.0000, "U":0}
{"time":1431654137, "OD":-0.0015, "Z":0.0000, "U":0}
3 个评论
采纳的回答
Stephen23
2015-5-17
编辑:Stephen23
2015-5-17
It is not clear exactly how this file is formatted, as the text on the page is not a good way to represent files. Please upload the actual data file.
Based on the text in the question I created a small data file (attached), and then a small script containing this code:
fmt = ['{',repmat('%*s%f',1,4),'}'];
fid = fopen('temp.txt','rt');
A = cell2mat(textscan(fid,fmt,'Delimiter',':,'));
fclose(fid);
Which reads all of the numeric data correctly:
>> A
A =
1.4317e+009 0.001 0 0
1.4317e+009 0.0007 0 0
1.4317e+009 -0.0005 0 0
1.4317e+009 -0.0015 0 0
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Export 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!