我有一个大的csv文件(应该是大约100万行),其中包含具有以下结构的选项数据(内容被更改):
secid, date, days, delta, impl_volatility, impl_strike, impl_premium, dispersion, cp_flag, ticker, index_flag, industry_group
100000, 02/05/1986, 60, -80, 0.270556, 74.2511, 5.2415, 0.021514, C, ASC, 0, 481
100000, 03/05/1986, 30, -40, 0.251556, 74.2571, 6.2415, 0.025524, P, ASC, 0, 481
Run Code Online (Sandbox Code Playgroud)
我使用以下方法成功导入了测试文件:
ftest = fopen('test.csv');
C = textscan(ftest,'%f %s %f %f %f %f %f %f %s %s %f %f','Headerlines',1,'Delimiter',',');
fclose(ftest);
Run Code Online (Sandbox Code Playgroud)
但是,C是一个单元格数组,这使得在matlab中处理文件内容变得更加困难.将它作为"常规"数组更容易(原谅我不知道正确的命名法,我刚开始使用matlab).
如果我输出C,我得到:
Columns 1 through 6
[2x1 double] {2x1 cell} [2x1 double] [2x1 double] [2x1 double] [2x1 double]
Columns 7 through 12
[2x1 double] …
Run Code Online (Sandbox Code Playgroud)