简体   繁体   English

在八度中读取CSV时出现问题

[英]Problems reading CSV in Octave

I have a .csv file and I can't read it on Octave. 我有一个.csv文件,但无法在Octave上阅读。 On RI just use the command below and everything is read alright: 在RI上,只需使用下面的命令,一切就可以了:

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

However, when I go to Octave it doesn't do it properly with the below command: 但是,当我转到Octave时,无法使用以下命令正确执行此操作:

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

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 (ie Column3) from the first value (ie Value1) and the same thing happens with the last value of the first row (ie Value3) and the first value of the second row (ie Value4) 注意,没有逗号将最后一个列名(即Column3)与第一个值(即Value1)分开,并且第一行的最后一个值(即Value3)和第二行的第一个值(即Value4)

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

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

Alex's answers already explains why csvread does not work for your case. 亚历克斯的答案已经解释了为什么csvread对您的情况不起作用。 That function only reads numeric data and returns an array. 该函数仅读取数字数据并返回一个数组。 Since your fields are all strings, you need something that reads a csv file into a cell array. 由于您的字段都是字符串,因此您需要将csv文件读入单元格数组的内容。

That function is named csv2cell and is part of the io package . 该函数名为csv2cell ,是io软件包的一部分。

As a separate note, if you plan to make operation with those dates, you may want to convert those dates as strings, into serial date numbers. 另外,如果计划使用这些日期进行操作,则可能需要将这些日期作为字符串转换为序列日期数字。 This will allow you to put your dates in a numeric array which will allow for faster operations and reduced memory usage. 这将使您可以将日期放入数字数组中,从而可以加快操作速度并减少内存使用量。 Also, the financial package has many functions to deal with dates. 同样, financial包具有许多处理日期的功能。

csvread only reads numeric data, so a date does not qualify unfortunately. csvread仅读取数字数据,因此不幸的是日期没有资格。

In Octave you might want to check out the dataframe package. 在Octave中,您可能需要检出数据框包。 In Matlab you would do readtable . 在Matlab中,您将执行readtable

Otherwise there are also more primitive functions you can use like textscan . 否则,还有更多原始函数可以使用,例如textscan

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

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