calendar
Calendar matrix for a month.
Category: Language Fundamentals > Data Types
Syntax
c = calendar
Calendar of the current month.
c = calendar(y, m)
Calendar for year y and month m.
c = calendar(d)
Calendar for the month containing the datenum d.
Description
The first row contains the first of the month in the column of its weekday. Days follow row by row, and cells before the 1st and after the last day hold zero. Six rows are always returned, so some months leave the last row empty.
In MATLAB, calling calendar without an output argument draws a text calendar in the Command Window. Request the matrix when you need to process it.
Input arguments
y, m- Year and month numbers.
d- Serial date number from
datenum.
Output arguments
c- 6-by-7 matrix. Columns run Sunday to Saturday; each entry is the day of the month, or
0for blank cells.
Example
February 2024
c = calendar(2024, 2)
c(1, 5)
Output
c = 6×7
0 0 0 0 1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 0 0
0 0 0 0 0 0 0
ans = 1
Feb 1, 2024 is a Thursday, the fifth column.
Notes
Use the output form c = calendar(...); the printed text calendar is not drawn in MatLivre.