【问题标题】:Loading CSV file into Octave/MATLAB将 CSV 文件加载到 Octave/MATLAB
【发布时间】:2013-06-27 02:31:42
【问题描述】:

数据

假设以下数据格式(第一行有标题行,500+行):

数字,数字,数字,字符串,字符串,数字,数字,数字,字符串,数字,数字,数字

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

我的密码:

忽略第 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");

错误:

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

我是 octave 的新手,无法理解错误的原因。请指导。

【问题讨论】:

  • ...,"headerlines","1") 应该是...,"headerlines",1)
  • 没错。虽然格式有点乱。使用 %q 会报错:strread: A(I): index out of bounds; value 1 out of bound 0

标签: matlab csv machine-learning octave


【解决方案1】:

除了上面提到的headerlines的问题,你有13个转换规范但只有12列,第9列应该对应一个%*s,而不是两个。 如果我将格式字符串更改为

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

在 Matlab 中解析一个小样本文件可以正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-03
    • 2014-10-09
    • 1970-01-01
    • 2011-11-02
    • 1970-01-01
    • 2022-01-09
    • 2019-01-04
    • 1970-01-01
    相关资源
    最近更新 更多