Excel到matlab的时间戳

时间:2013-05-02 14:19:09

标签: excel matlab

我在excel中有时间戳形式的数据,看起来像是

30/11/12 12:42 AM
30/11/12 12:47 AM
30/11/12 12:56 AM
30/11/12 1:01 AM

我需要让它到matlab看起来像这样

dateStrings = {...
'30/11/12 12:42 AM' ...
'30/11/12 12:47 AM' ...
'30/11/12 12:56 AM' ...
'30/11/12 1:01 AM' ...
 };

我尝试过xlsread,但它没有输入字符串。

2 个答案:

答案 0 :(得分:0)

我设法找到解决问题的方法

1. Copy and paste your dates into Excel in dd-mm-yyyy format
2. In Excel, highlight the data and go Right Click, Format Cells/Number
3. In Matlab go a=xlsread(xlsfile);
4. Type datestr(a+693960)

答案 1 :(得分:0)

以下适用于我(在Octave中,但在MATLAB中应该相同):

>> [num,txt,raw]=xlsread('dates.xls','A1:A4')
num =

  4.1243e+004
  4.1243e+004
  4.1243e+004
  4.1243e+004

txt = {}(0x0)
raw =
{
  [1,1] = 4.1243e+004
  [2,1] = 4.1243e+004
  [3,1] = 4.1243e+004
  [4,1] = 4.1243e+004
}

>> datestr(num+datenum(1900,1,1,0,0,0)-2)
ans =

30-Nov-2012 00:42:00
30-Nov-2012 00:47:00
30-Nov-2012 00:56:00
30-Nov-2012 01:01:00

>> whos ans
Variables in the current scope:

Attr Name        Size                     Bytes  Class
==== ====        ====                     =====  =====
    ans         4x20                        80  char

Total is 80 elements using 80 bytes

查看各种输出格式选项的datestr功能。

阿诺