MATLAB Answers

converting a date column with yyyymmdd to matlab date number?

19 ビュー (過去 30 日間)
Danielle Leblance
Danielle Leblance 2018 年 5 月 6 日
回答済み: Peter Perkins 2018 年 5 月 14 日
Hi ,
I have a double(not a string)column where each observation is a number with the following format yyyymmdd.How can I convert this column to a column of matlab date numbers. for example, how can I convert 19960530 to 729175

  0 件のコメント

Sign in to comment.

採用された回答

Star Strider
Star Strider 2018 年 5 月 6 日
This seems to work:
ymdCol = [19960530; 19960531; 19960601; 19960602] % Create Column
DN = datenum(num2str(ymdCol), 'yyyymmdd')
ymdCol =
19960530
19960531
19960601
19960602
DN =
729175
729176
729177
729178

  0 件のコメント

Sign in to comment.

その他の回答 (1 件)

Peter Perkins
Peter Perkins 2018 年 5 月 14 日
Danielle, you may have your reasons for wanting a datenum, but I'd suggest using datetime, for which there's an easy conversion:
>> datetime([19960530;19960531],'ConvertFrom','yyyymmdd')
ans =
2×1 datetime array
30-May-1996 00:00:00
31-May-1996 00:00:00

  0 件のコメント

Sign in to comment.

タグ


Translated by