在.csv文件中的Matlab中使用textscan [英] Using textscan in Matlab on .csv files
问题描述
我希望有人可以通过textscan(或Matlab中的某些其他功能)帮助我读取文件.在线文档和示例对我无济于事,我想我缺少直观的东西了:(这就是我要阅读的文件结构:
I was hoping someone might be able to help me with reading in a file with textscan (or some other function in Matlab). The documentation and examples online have been no help to me and I guess I am missing something intuitive :( Here is what the structure of the file I want to read in looks like:
ID, Date of ID, C 1-1, C 1-2, M R3, M R4, Glob ID Settings
TPOL_430_412_10X, 5/5/2011 20:23, 0, 0, 0, 0, -1, 5.00_5.00_3_300.00_3_0.00
TPOL_430_412_10X, 5/5/2011 20:23, 0, 0, 0, 0, -1, 5.00_5.00_3_300.00_3_0.00
TPOL_430_412_10X, 5/5/2011 20:23, 0, 0, 1, 0, 1, 5.00_5.00_3_300.00_3_0.00
TPOL_430_412_10X, 5/5/2011 20:23 0, 0, 0, 0, -1, 5.00_5.00_3_300.00_3_0.00
TPOL_430_412_10X, 5/5/2011 20:23 0, 0, 0, 0, -1, 5.00_5.00_3_300.00_3_0.00
我的文件是.csv文件,因此分隔符是逗号.我一直无济于事的是:
Where my file is a .csv file so the delimiter is a comma. What I have been trying to no avail is the following:
fmt = [repmat('%s',1,2), repmat('%f',1,5),'%*s %[^\n]'];
fid = fopen('file.csv','rt');
data = textscan(fid, fmt, 'HeaderLines', 1);
fclose(fid);
任何建议,我们将不胜感激!
Any suggestions greatly appreciated!
推荐答案
我用了这个
A = textscan(fid,'%s %s %s %f %f %f %f %f %s', 'HeaderLines', 1);
它应该将要读取的所有参数拆分为大小为(1,9)
的单元格A
.
it should split all the parameters you want to read into a cell A
with size (1,9)
.
希望这会有所帮助.
这篇关于在.csv文件中的Matlab中使用textscan的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!