简体   繁体   English

将CSV文件加载到Octave / MATLAB中

[英]Loading CSV file into Octave/MATLAB

DATA : 数据

Assume the following data format (with a header line in the first row, 500+ rows): 假定以下数据格式(第一行中有标题行,超过500行):

Number, Number, Number, String, String, Number, Number, Number, String, Number, Number, Number 数字,数字,数字,字符串,字符串,数字,数字,数字,字符串,数字,数字,数字

Example: 1,0,3,"Braund, Mr. Owen Harris",male,22,1,0,A/5 21171,7.25,C85,S 例如: 1,0,3,"Braund, Mr. Owen Harris",male,22,1,0,A/5 21171,7.25,C85,S

MY CODE: 我的密码:

Ignoring the columns 4, 9, 11 and 12(index starting from 1). 忽略第4、9、11和12列(索引从1开始)。

[A, B, C, D, E, F, G, H] = textread("train.csv","%d %d %d %*q %s %d %d %d %*s %*s %f %*s %*s","delimiter",",","endofline","\n","headerlines","1");

THE ERROR: 错误:

error: invalid conversion from string to real scalar
error: fskipl: invalid number of lines specified
error: called from:
error:   /usr/share/octave/3.6.4/m/io/textread.m at line 71, column 5

I am new to octave and unable to understand the cause of the error. 我是八度的新手,无法理解错误的原因。 Please guide. 请指导。

Except for the issue with headerlines mentioned above, you have got 13 conversion specifications but only 12 columns, column 9 should correspond to one %*s , not two. 除了上述headerlines的问题之外,您已经获得13个转换规范,但只有12列,第9列应对应一个%*s ,而不是两个。 If I change the format string to 如果我将格式字符串更改为

%d %d %d %*q %s %d %d %d %*s %f %*s %*s

parsing a small sample file works as expected in Matlab. 解析一个小的示例文件可以在Matlab中按预期进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM