Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

import data from excel into matlab gives false date

Asked by Locks

Locks

on 10 Apr 2013
Accepted Answer by Leah

Leah

hi, I have importet data from excel into matlab using the following code:

filename = 'vola_regimes.xlsx';
sheet = 1;
xlRange_d = 'C4:C132';
xlRange_sp='D4:D132';
xlRange_dV = 'H4:H132';
xlRange_VIX='I4:I132';
date_SP = xlsread(filename, sheet, xlRange_d)
SP = xlsread(filename, sheet, xlRange_sp)
date_VIX = xlsread(filename, sheet, xlRange_dV)
VIX = xlsread(filename, sheet, xlRange_VIX)

That is working perfectly, but the problem is that range C4:C132 and H4:H132 are both dates. the import fuction didn't work ant therefore I changed the format in excel to general instead of date. then I am able to imporat the data, but from what I can see when I use the datestr function, matlab is not recognizing the data correctly and instead of 05.08.2002 it gives me 06-Aug-0102

Is there a way to change that?

0 Comments

Locks

Locks

Products

No products are associated with this question.

1 Answer

Answer by Leah

Leah

on 10 Apr 2013
Edited by Leah

Leah

on 10 Apr 2013
Accepted answer

matlab and excel use different dates to as a starting reference. You just have to add 693960 to the excel date numbers

Excel: 1 represents 1/1/1900 12:00:00 a.m

Matlab: 1 represents 01-Jan-0000

SAS: 0 represents January 1, 1960

Legend has it that the founders of SAS wanted to use the approximate birth date of the IBM 370 system... cute, but annoying

1 Comment

Locks

Locks

on 10 Apr 2013

perfect, thanks!

Leah

Leah

Contact us