Dates from Excel Spreadsheet won't import into MATLAB

6 次查看(过去 30 天)
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.

回答(1 个)

Jan
Jan 2011-8-28
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 个评论
Don
Don 2011-8-28
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 2011-8-28
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.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by