Dates from Excel Spreadsheet won't import into MATLAB

6 vues (au cours des 30 derniers jours)
Don
Don le 27 Août 2011
Hi all, thanks for the answers to my previous questions.
I have an Excel 2007 file with a column of dates of the visual format 5/21/2011. When I right-click and click on Format cell, it shows that it is of type "date." I then have 3 columns of numbers. When I try both xlsread('name_of_file') or in MATLAB "Edit," then "Paste to Workspace," it only shows the 3 columns of numbers and doesn't even show the dates.
I also tried to copy JUST the dates and paste it into MATLAB and then try to combine the other info but when I try to paste the dates from within MATLAB to the file with the numbers I get the error message "numeric arrays cannot contain strings." It seems that when I can get the dates to enter MATLAB they enter as a string instead of a date number.
Would appreciate any help.

Réponses (1)

Jan
Jan le 28 Août 2011
Are you able to import the dates as serial date numbers, e.g. by formatting them in Excel to this format? Then you can convert the numbers from Excel's to Matlab's serial date number format by adding 693962 (for Excel on PC, on Macs Microsoft decided to start 4 years later and you have to add 695422). See also X2MDATE.
Or can you import the Excel dates as strings. Than DATENUM will assist you at the conversion.
  2 commentaires
Don
Don le 28 Août 2011
I think the Excel dates are already in serial date number format because when I click on Format Cells, it shows date format, and as I understand it, this means that it is encoded as a serial date number but I have multiple ways to visualize it?
In case it wasn't I did try using =datevalue(cell) to convert it to a serial date number but I get an error message.
Fangjun Jiang
Fangjun Jiang le 28 Août 2011
Should use datestr(). Please give a snip of the data you got in MATLAB. It's much easier to talk about if you give some examples.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by