Time data import from Excel

14 ビュー (過去 30 日間)
N =B>=>2
N =B>=>2 2013 年 4 月 25 日
編集済み: per isakson 2019 年 11 月 11 日
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?

回答 (2 件)

per isakson
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 件のコメント
N =B>=>2
N =B>=>2 2013 年 4 月 25 日
My timedate in Excel looks like 09:04:23. When I import it in Matlab, it looks like 40148. It is in a matrix with some other columns also. Then I use datestr:
Time = datestr(whatever, 'HH:MM:SS')
After this the data looks like 09:00:23, but it is char, and I cannot use it in my matrix with the other info, it has to be double. And this is where my problem is, I cannot convert char into double
per isakson
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
MUHAMMAD NAEEM FAIZ 2019 年 11 月 11 日
Hi,
I have data in excel file. How to convert my data into Timetable ?
  1 件のコメント
Walter Roberson
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 ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by