Converting Date and Time to Number

24 ビュー (過去 30 日間)
Justin Duval
Justin Duval 2015 年 2 月 11 日
コメント済み: Star Strider 2015 年 2 月 11 日
Hi guys,
I have read in a column of dates and times from an excel document using xlsread and now have a cell of dates in the form 'yyyy-mm-dd hh:mm:ss AM/PM'.
I would like to extract from this cell a vector with the time in the form hhmm. How might I go about doing this?
Thanks,
Justin

採用された回答

Star Strider
Star Strider 2015 年 2 月 11 日
See datenum, datestr and their friends.
  5 件のコメント
Justin Duval
Justin Duval 2015 年 2 月 11 日
編集済み: Justin Duval 2015 年 2 月 11 日
Of course I've come across another obstacle. I now have my time data in the HHMM form I need it in, but as a char. Is it possible to convert this vector of char data into a vector of numerical data?
EDIT: Scratch that. I converted the character array to a cell array using cellstr, and converted that to a numerical vector using str2double.
IF there is a smarter way to do this, please let me know. Thanks again for your help!
Justin
Star Strider
Star Strider 2015 年 2 月 11 日
My pleasure!
If you want the date fields as numeric, use the datevec function:
dt = {'2014-02-10 10:15:27 PM'}; % Original Date
dn = datenum(dt, 'yyyy-mm-dd HH:MM:SS AM'); % Date Number
tv = datevec(dn); % Date Vector
hhmm = tv(:,4:5) % Get Hour & Minute Fields
produces:
hhmm =
22 15

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by