Time data import from Excel
18 次查看(过去 30 天)
显示 更早的评论
I am importing data from Excel and one of the columns is with time stamps in the format 09:00:15 etc. I import it with XLS read, then I use datestr in order to convert the numbers in decimals Matlab gives me into proper time values. Then the resulting variable is char and I cannot use it, since I need it to be double. str2double does not do the job for me, it gives me NaN or Inf. Any suggestions?
0 个评论
回答(2 个)
per isakson
2013-4-25
编辑:per isakson
2013-4-25
then I use datestr in order to convert the numbers in decimals Matlab gives me into proper time values
does that mean something like
str = datestr( numbers, 'HH:MM:SS' );
then you need
num = datenum( str, 'HH:MM:SS' );
no I don't understand what you do. Why do you use datestr?
2 个评论
per isakson
2013-4-25
编辑:per isakson
2019-11-11
I think "40148" is the number of days since 1900-01-01 or 1899-12-31
>> datestr( (40148+datenum( 1900, 1, 1 )), 'yyyy-mm-dd HH:MM:SS' )
ans =
2009-12-03 00:00:00
The time information is lost? some other columns also is that there the time information hides?
Excel help says:
The integer portion of the number, ddddd, represents the number of days
since 1900-Jan-0. For example, the date 19-Jan-2000 is stored as 36,544,
since 36,544 days have passed since 1900-Jan-0. The number 1 represents
1900-Jan-1. It should be noted that the number 0 does not represent
1899-Dec-31. It does not. If you use the MONTH function with the date 0,
it will return January, not December. Moreover, the YEAR function will
return 1900, not 1899.
MUHAMMAD NAEEM FAIZ
2019-11-11
Hi,
I have data in excel file. How to convert my data into Timetable ?
1 个评论
Walter Roberson
2019-11-11
T = readtable('NameOfFIle.xls');
If you are using a relatively new release, you might end up with one column being a datetime object and another column being a duration object. If so, then add the two together to get full precision datetime results.
If you are using a slightly older release, you might end up with a column being a datetime object and another column being a cell array of character vectors that represent time of day. If so then often the easiest way to proceed is to text processing to isolate the digits, convert them to numeric, and pass the numbers to duration(). For example,
foo = cell2mat(cellfun(@(S) sscanf( S, '%d:%d:%d').', {'12:34:56'; '11:22:33'}, 'uniform', 0))
dur = duration(foo(:,1),foo(:,2),foo(:,3));
and then add to the datetime array.
Once you have a suitable time vector built, you can use table2timetable() indicating the time vector as the 'RowTimes'
另请参阅
类别
在 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!