xlsread not extracting formatted content

2 Ansichten (letzte 30 Tage)
ScottPT303
ScottPT303 am 30 Jun. 2015
Kommentiert: Star Strider am 30 Jun. 2015
I'm trying to use the xlsread function to extract a column of dates/times in a custom format. The original date format of the cell is "M/D/YY H:MM AM/PM". My custom format is "DD MMM YYYY HH:MM:SS.000" (because this is the format that STK/Matlab Object-model recognizes).
[~,dateTimeFixArray,~] = xlsread(filename,'D2:D1000')
When I use xlsread to import the data as a str I get an array in the original format instead of my custom format. Is there any way to force xlsread to extract my custom format instead?

Antworten (1)

Star Strider
Star Strider am 30 Jun. 2015
The xlsread function uses Excel to read the contents of the file. If you want the dates and times in your custom format, first convert them to MATLAB date numbers with datenum, then convert them to your custom date strings with datestr.
  2 Kommentare
ScottPT303
ScottPT303 am 30 Jun. 2015
Thanks the response. Doing the formatting in Matlab after pulling the content from excel is what I've been doing so far. My problem is that I'm working with very large data sets and I'd rather do the date/time formatting once in the excel file instead of looping through the dateTimeFixArray in Matlab to format. That way if I have to re-run my Matlab script I don't have to reformat again since its already been done on the excel side.
Maybe Matlab doesn't have this function, but is there any way using xlsread or some other function to import my content as already formatted?
Star Strider
Star Strider am 30 Jun. 2015
My pleasure.
Not to my knowledge. The easiest way might be to use the Excel custom date format options and format the date column in every Excel file in the format you want. (You might be able to do that through MATLAB, but that could involve some significant ‘ActiveX’ programming that I’ve only read about in a few threads here. I’ve no experience with it.)
If I wanted to export the date in a particular format, I would do it in Excel and then not bother with the date string format conversions in MATLAB.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by