Why Matlab doesn't recognize the time variable from .xlsx file
10 次查看(过去 30 天)
显示 更早的评论
I need to have 1 information per second of the time, which is why i have to compare times and remove the unnecessary ones. But Matlab doesn't recognize the column with the Time variable, even though the formating in excel is done right. Can anyone help with this ?
1 个评论
Rik
2020-6-22
What exact code are you using to read this excel file? Excel can be very picky about the locale settings. To reproduce your issue it may also be needed to know the language you have your OS set to (and the date/time settings), as well as the language your Office is set to. Thanks Microsoft...
采纳的回答
Star Strider
2020-6-22
I have no idea why datetime cannot import the time correctly in that format. The readtable function imports it a fractions of a day.
A small diversion into datevec and it works:
T1 = readtable('test.xlsx');
T1.Time = datetime(datevec(T1.Time), 'Format','HH:mm:ss'); % Original Table
T2 = table(T1.Date + timeofday(T1.Time), 'VariableNames',{'Date_Time'}); % Create New Variable
T2 = [T2 T1(:,3:end)] % Derived Table
and:
Sample = T2(1:10,:)
displays:
Sample =
10×3 table
Date_Time Angle Speed
____________________ _____ _____
01-Feb-2014 00:00:00 62 3.6
01-Feb-2014 00:00:00 62 3.8
01-Feb-2014 00:00:01 60 4.1
01-Feb-2014 00:00:01 59 4.2
01-Feb-2014 00:00:02 58 4.3
01-Feb-2014 00:00:02 60 4.3
01-Feb-2014 00:00:02 64 4.3
01-Feb-2014 00:00:03 63 4.3
01-Feb-2014 00:00:03 61 4.3
01-Feb-2014 00:00:04 61 4.3
The original ‘T1’ table keeps the dates and times in separate columns. The ‘T2’ table concatenates them.
.
7 个评论
Star Strider
2020-6-22
As always, my pleasure!
I have no control over any Windows settings other than my own.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!