datenum on array of values - specifying the format

조회 수: 2 (최근 30일)
dormant
dormant 2021년 10월 15일
댓글: Lei Hou 2021년 10월 18일
I can't seem to specify the format for datenum when I passi an array of values.
Here is a snippet of my code:
formatIn = 'dd/mm/yyyy HH:MM';
X = readtable( fileRain );
datimR = datenum(X.DateTime_LT_,formatIn);
This returns an error:
Error using datetime/datenum
Too many input arguments.
Error in plot_rsam_rain (line 12)
datimR = datenum(X.DateTime_LT_,formatIn);
It works fine when I don't specify the format in the call to datetime, but the values are all wrong as it assumes 'mm/dd/yyyy'.
Any suggestions how I can get this to work.
  댓글 수: 1
Lei Hou
Lei Hou 2021년 10월 18일
Hi Dormant,
May I know why you want to convert datetime to datenum? Now, it is more recommended to use the morden datatype datetime than datenum. Actually, datenum is put into discourage use.
Thanks,
Lei

댓글을 달려면 로그인하십시오.

답변 (1개)

Cris LaPierre
Cris LaPierre 2021년 10월 15일
편집: Cris LaPierre 2021년 10월 15일
You do not need to enter a format if your data is already a datetime. The 'FormatIn' flag should only be used if your date is a string.
  • DateNumber = datenum(DateString,formatIn)
DateNumber = datenum(t) converts the datetime or duration values in the input array t to serial date numbers.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by