Import date into Matlab

I am trying to import an excel file to Matlab but it is importing date wrong. The original file looks as follows:

1947-04-01 0.064049 1947-07-01 -0.018689 1947-10-01 -0.046279 1948-01-01 -0.023242 1948-04-01 0.009531 1948-07-01 0.034058

I save it as data_jmp.xlsx. When I import it using xlsread it gives me :

T = xlsread('data_jmp.xlsx')

T =

   1.0e+04 *
    1.5706    0.0004
    1.5796    0.0004
    1.5887    0.0004
    1.5979    0.0004
    1.6071    0.0004
    1.6162    0.0004

How do I convert these numbers into the initial dates? Then I need to plot the second column versus the first column.

Answers (1)

Adelia
Adelia on 21 Oct 2018

0 votes

I figured out how to fix it.
t1 = datestr((T(:,1) +datenum(1904, 1,1)), 'yyyy-mm-dd')
t2 = T(:,2);
But now I still get an error when using:
plot(t1, t2)
Invalid first data argument.
I suppose this has to do with the dates not being specified as numbers.

Asked:

on 21 Oct 2018

Answered:

on 21 Oct 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!