在 Octave 中读取 CSV 的问题 [英] Problems reading CSV in Octave

查看:389
本文介绍了在 Octave 中读取 CSV 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .csv 文件,但无法在 Octave 上读取.在 R 上,我只使用下面的命令,一切正常:

I have a .csv file and I can't read it on Octave. On R I just use the command below and everything is read alright:

myData <- read.csv("myData.csv", stringsAsFactors = FALSE)

但是,当我使用以下命令进入 Octave 时,它​​无法正确执行:

However, when I go to Octave it doesn't do it properly with the below command:

myData = csvread('myData.csv',1,0);

当我用记事本打开文件时,数据如下所示.请注意,最后一列名称(即 Column3)与第一个值(即 Value1)之间没有逗号分隔,并且第一行的最后一个值(即 Value3)和第二行的第一个值(即值4)

When I open the file with Notepad, the data looks something like the below. Note there isn't a comma separating the last column name (i.e. Column3) from the first value (i.e. Value1) and the same thing happens with the last value of the first row (i.e. Value3) and the first value of the second row (i.e Value4)

Column1,Column2,Column3Value1,Value2,Value3Value4,Value5,Value6

Column1 用于日期值(格式为 yyyy-mm-dd hh:mm:ss),我不知道这是否与问题有关.

The Column1 is meant for date values (with format yyyy-mm-dd hh:mm:ss), I don't know if that has anything to do with the problem.

推荐答案

csvread 只读取数字数据,所以不幸的是日期不符合条件.

csvread only reads numeric data, so a date does not qualify unfortunately.

在 Octave 中,您可能想要查看 dataframe 包.在 Matlab 中你会做 readtable.

In Octave you might want to check out the dataframe package. In Matlab you would do readtable.

否则,您还可以使用更多原始函数,例如 textscan.

Otherwise there are also more primitive functions you can use like textscan.

这篇关于在 Octave 中读取 CSV 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆