Convert clock time to decimal

28 ビュー (過去 30 日間)
Faria Imam
Faria Imam 2016 年 6 月 6 日
コメント済み: Etikaf Hussain 2019 年 5 月 11 日
Hi, I want to convert cell2mat, but there are some times (clock time) values in my data. That's why I couldn't convert it. How can I convert time value to decimal? Is there any other way to convert in to matrix without changing the time value in to decimal? My time value format is hh:mm:ss.

回答 (2 件)

Star Strider
Star Strider 2016 年 6 月 6 日
編集済み: Star Strider 2016 年 6 月 6 日
Use the datenum function on your ‘clock time’ values. If you just want the time of day, the fractional numbers (the part of the date number to the right of the decimal) are in decimal fractions of a day, so you need to do no other conversions. Get the day fraction by using the rem or mod functions.
Example:
t = {'12:34:56'};
dnt = datenum(t)
day_frac = rem(dnt,1)
dnt =
736330.524259259
day_frac =
0.524259259225801
EDIT You can of course combine these into one assignment:
day_frac = rem(datenum(t),1)
  3 件のコメント
Walter Roberson
Walter Roberson 2018 年 4 月 4 日
Please show your code
Etikaf Hussain
Etikaf Hussain 2019 年 5 月 11 日
This may be of help:
datetime(x,'ConvertFrom','excel')
where x is the array containing time values.

サインインしてコメントする。


Peter Perkins
Peter Perkins 2018 年 4 月 4 日
It sounds very likely that you have some sort of table in Excel that has columns of numbers and also a column of times. If that is true, your best bet is to use readtable to bring them into MATLAB. It's really hard to say how the times will be read in, it depends on how they are stored in the spreadsheet. Likely as text, in which case you will want to convert them to datetimes or durations.

カテゴリ

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