Main Content

calquarters

Calendar duration in quarters

Description

The calquarters function returns an array that represents calendar quarters. When you use arrays that have the calendarDuration data type in calendar calculations, the calculations take into account leap years, Daylight Saving Time shifts, and the differing lengths of calendar months. For calculations that involve fixed lengths of time, use the duration data type.

Q = calquarters(X) returns an array representing calendar quarters equivalent to the values in array X.

  • If X is a numeric array, then Q is a calendarDuration array with each element equal to the number of calendar quarters in the corresponding element of X.

  • If X is a calendarDuration array, then Q is a double array with each element equal to the number of whole calendar quarters in the corresponding element of X.

    Q = fix(calmonths(t)/3)

example

Examples

collapse all

X = magic(4);
Q = calquarters(X)
Q = 4x4 calendarDuration
   16q    2q    3q   13q
    5q   11q   10q    8q
    9q    7q    6q   12q
    4q   14q   15q    1q

Create an array of calendar durations. Then, convert each value to the equivalent number of whole calendar quarters.

X = calmonths(2:2:6) + caldays(8)
X = 1x3 calendarDuration
   2mo 8d   4mo 8d   6mo 8d

Q = calquarters(X)
Q = 1×3

     0     1     2

Input Arguments

collapse all

Input array, specified as a numeric array, calendar duration array, or logical array. If X is a numeric array, it must contain only integer values. That is, you cannot create fractional calendar units.

Extended Capabilities

Thread-Based Environment
Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

Version History

Introduced in R2014b