Importing HH:MM:SS from excel
10 次查看(过去 30 天)
显示 更早的评论
So I have an excel file with a column of time in format HH:MM:SS. I imported this column into Matlab by choosing ''Number'' in the Import Data tool in Matlab and called this imported column''Time''. Then I used the datestr(Time,'HH:MM:SS') command to convert my imported column Time into the HH:MM:SS format but the problem is it converts it to a 300x8 char. The conversion is correct in that I get everything in HH:MM:SS format but it isn't in the regular format (with the symbol of 4 small squares in the workspace, instead I have a square with'abc' inside it). Not sure what char is exactly but I want it in 300x1 format so that I can plot it because at the moment I can't.
Any ideas?
Thanks
0 个评论
采纳的回答
Peter Perkins
2016-3-11
datestr is the (old) command to create strings that represent dates and times. So that's why you have a char array. If you import as numbers, you'll get time in units of days (that how Excel stores them), and so you might see something like
>> Time
Time =
0.04309
0.12784
0.21258
You have not provided enough information to go on, but as Ahmet says, since R2014b datetime and duration are probably a better choice than using datestr. One thing you might do is this:
>> d = days(Time)
d =
0.04309 days
0.12784 days
0.21258 days
>> d.Format = 'hh:mm:ss'
d =
01:02:03
03:04:05
05:06:07
>> plot(d,1:3)
0 个评论
更多回答(2 个)
Ahmet Cecen
2016-3-10
编辑:Ahmet Cecen
2016-3-10
If you are using the import tool, use datetime, as in import as datetime initially. Then you will be able to access individual components like Data.Hour etc.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!