简体   繁体   English

从 Octave 中的 CSV 文件中读取日期

[英]Reading Date from CSV file in Octave

I want to read a CSV file in Octave which has a date column and 4 columns which are integers.我想在 Octave 中读取 CSV 文件,该文件有一个日期列和 4 个整数列。 I have used.我用过。

[num,txt,raw] = dlmread('Mitteilungen_data.csv');
ID = num(:,1) ;
DATE = datestr (date, yyyy-mm-dd) ;
FK_OBSERVERS= num(:,2) ;
GROUPS = num(:,3) ;
SUNSPOTS = num(:,4) ;
WOLF = num(:,5) ;
dn=datenum(DATE,'YYYY-MM-DD');
plot(dn,WOLF)

Sample Data:样本数据:

 ID DATE FK_OBSERVERS GROUPS SUNSPOTS WOLF 4939 1612-01-17 11 5 11 61 83855 1612-01-18 85 2 2 22 4940 1612-01-20 11 4 5 45 4941 1612-01-21 11 4 7 47 4942 1612-01-23 11 3 5 35 4943 1612-01-24 11 3 6 36 4944 1612-01-25 11 6 13 73 4945 1612-01-27 11 3 6 36 83856 1612-01-28 85 NULL NULL NULL 4946 1612-01-29 11 3 6 36 4947 1612-01-30 11 4 8 48 4948 1612-02-02 11 5 8 58 4949 1612-02-05 11 4 7 47 4950 1612-02-06 11 3 7 37 4951 1612-02-10 11 5 7 57 4952 1612-02-12 11 3 4 34 4953 1612-02-13 11 2 2 22 4954 1612-02-14 11 3 3 33

The Date column is showing an error: element number 2 undefined in return list .日期列显示错误: element number 2 undefined in return list How can I fix this?我怎样才能解决这个问题?

You are using您正在使用

[num, txt, raw] = dlmread( %...

but dlmread does not return three outputs.但 dlmread 不返回三个输出。 Type help dlmread in your console to see the syntax.在控制台中键入help dlmread以查看语法。

What does seem to return these three arguments is the xlsread command.似乎返回这三个 arguments 的是xlsread命令。 Perhaps you copied code that used xlsread?也许您复制了使用 xlsread 的代码?

However, even so, I would still use csv2cell .但是,即便如此,我仍然会使用csv2cell Type csv2cell('data.csv') (where data.csv is the name of your file) to see what kind of output it gives键入csv2cell('data.csv') (其中 data.csv 是您的文件的名称)以查看它给出的 output 类型

Before you can use any of the commands defined in the io package, you need to load it on your workspace.在您可以使用io package 中定义的任何命令之前,您需要将其加载到工作区中。

pkg load io

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

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