MATLAB Answers

Create month array?

조회 수: 33(최근 30일)
Julozert
Julozert 2020년 6월 1일
답변: Stephen 2021년 7월 14일
Hello,
Is it possible to create a datetime array with just entries from January to December?
I tried it like this but it did not work:
str = (1:12);
t = datetime(str(:),'InputFormat','mm');
I just want an array with 12 entries and each of them is a month with datatype "datetime"

답변(2개)

KSSV
KSSV 2021년 7월 14일
year = 2020 ;
t = datetime(year,1,1):dateime(year,12,31) ;

Stephen
Stephen 2021년 7월 14일
D = datetime(2021,1,1):calmonths(1):datetime(2021,12,31)
D = 1×12 datetime array
01-Jan-2021 01-Feb-2021 01-Mar-2021 01-Apr-2021 01-May-2021 01-Jun-2021 01-Jul-2021 01-Aug-2021 01-Sep-2021 01-Oct-2021 01-Nov-2021 01-Dec-2021
D.Format = 'MMM'
D = 1×12 datetime array
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by