Problem with importing Date & time from Excel
1 view (last 30 days)
Show older comments
Excel datas are these
2015-09-06 10:00:04 AM
2015-09-06 9:58:29 AM
date and time which in one line are in one cell. So I mean [2015-09-06 10:00] <- this is one cell in excel
I tried to import these date and time from excel to matlab by using xlsread fuction.
but I found that the form of data& time were changed like these
'2015-09-06 오전 10:00:04'
'2015-09-06 오전 9:58:29'
1. the date form is slitely changed [AM -> 오전]
I think matlab recognize the data form but it change in to Korean word.
How can I import excel date & time without changing it's form
2. and I tried to using datavec fucntion. but this error come out
Caused by:
[Error using datevec (line 247)
Too many time fields in 2015-09-06 오전 10:00:04.]
3. after all I do these to calculate gap between time and time
How can I do these?
0 Comments
Answers (2)
Walter Roberson
on 8 Sep 2015
It looks to me as if you are using R2014b or later and have configured the dates to be converted to datetime objects. If so then add the line
datetime.setDefaultFormats('default','yyyy-MM-dd h:mm:ss a')
and see if that helps. If I am correct then it is the display of the times that is being affected, not what is stored
If I am correct about it being datetime objects, then to find the difference between two times, just subtract them. You can assign a display format to the result:
timegap = time2 - time1;
timegap.Format = 'hh:mm:ss';
Peter Perkins
on 9 Sep 2015
Sangjun, it sounds like you're using a version of MATLAB prior to R2014b, so Walter's suggestion won't work.
I'm assuming your (Windows) machine is set to Korean/Korea. Excel does some funny things when localizing dates/times, and although you see things like 2015-09-06 10:00:04 AM when you view the spreadsheet, Excel actually returns things like 2015-09-06 오전 10:00:04 to MATLAB for the contents of those cells. (Strangely, when I created a spreadsheet and edited a date/time cell, Excel temporarily displayed the Korean characters for AM/PM, but then switched back when I was done editing.)
So: I think the simplest thing for you to do is to change the format of the cells in Excel to not use the AM/PM token.
0 Comments
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!