【问题标题】:Reading date-time data stored as Excel format into MATLAB将存储为 Excel 格式的日期时间数据读入 MATLAB
【发布时间】:2018-03-23 21:04:14
【问题描述】:

我有一个 csv 文件,其中包含一个 Excel 格式的数据时间列,以及另外两个浮动列; Excel 格式的日期包括自 1900 年 1 月 1 日以来的天数,例如,2 表示 1900 年 1 月 2 日,365 表示 1900 年 12 月 30 日,依此类推。

文件如下所示:

date,temp,value
41909.89,49.67,32
41910.67,49.16,36
41911.37,45.33,37

在 MATLAB 中读取此文件并将日期转换为日期时间格式的最佳方法是什么?

【问题讨论】:

  • 您是否已经在 Google 上搜索过“Excel 日期 Matlab”?第一次点击(无论如何对我来说)来自 Mathworks 网站,它准确地解释了你需要做什么。

标签: excel matlab datetime loaddata


【解决方案1】:

使用readtable 读取文件,然后使用datetime 转换日期。如果您有 Financial Toolbox,则可以使用 x2mdate 将 Excel 日期数字转换为 MATLAB 日期数字。如果不是,则偏移量取决于您在 Excel 中使用的日期格式。有关可能的偏移量的详细信息,请参阅x2mdate 的文档。

>> tbl = readtable('datafile.txt')
tbl =
  3×3 table
      date      temp     value
    ________    _____    _____
    41909.89    49.67    32   
    41910.67    49.16    36   
    41911.37    45.33    37   
>> tbl.date = datetime(tbl.date+693960,'ConvertFrom','Datenum')
tbl =
  3×3 table
            date            temp     value
    ____________________    _____    _____
    27-Sep-2014 21:21:36    49.67    32   
    28-Sep-2014 16:04:48    49.16    36   
    29-Sep-2014 08:52:48    45.33    37 

【讨论】:

    猜你喜欢
    • 2015-10-25
    • 2011-02-07
    • 1970-01-01
    • 1970-01-01
    • 2016-04-24
    • 2016-12-02
    • 2017-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多