The properties
Frequency
Frequency - The frequency of the dates
Incr
Incr - Place holder for the increment value for the dates
date_time
date_time - The date and time values represented as a datetime object
The methods
char
CHAR Convert date objects to formatted date strings.
s = char(obj) converts the date objects in the input array obj to formatted date strings using the default format based on the frequency of the dates. The formatted date strings are returned as a character array.
s = char(obj, format) converts the date objects to formatted date strings using the specified format. The format can be a character vector or a string.
Inputs: - obj: Array of date objects. - format: Format for the date strings (optional). If not provided, the default format based on the frequency of the dates is used.
Output: - s: Character array of formatted date strings.
Examples: - daily dates: d = rd(1990,1,25):rd(1990,6,25); disp(char(d)) - weekly dates: w = rw(1990,1):rw(1990,53); disp(char(w)) - monthly dates: m = rm(1990,1):rm(1990,12); disp(char(m)) - quarterly dates: q = rq(1990,1):rq(1990,4); disp(char(q)) - half-yearly dates: h = rh(1990,1):rh(1995,2); disp(char(h)) - yearly dates: y = ry(1990):ry(1995); disp(char(y)) - annual dates: a = ra(1990):ra(1995); disp(char(a))
colon
colon Creates an array of dates using the colon operator.
- Usage:
dateArray = colon(obj1, obj2)
- Inputs:
obj1: The starting date object.
obj2: The ending date object.
- Outputs:
dateArray: An array of dates spanning from obj1 to obj2.
- Example:
dates = obj1 : obj2;
See also rise_dates.dates.
convert
convert Converts the dates to a different frequency.
Usage:
d = convert(d, freq)
Inputs:
d: The date object.
- freq: The target frequency to convert the dates to. Valid values are
‘D’ (daily), ‘W’ (weekly), ‘M’ (monthly), ‘Q’ (quarterly), ‘H’ (half-yearly), and ‘Y’ (yearly).
Outputs:
d: The date object with dates converted to the specified frequency.
Example:
newDateObj = convert(dateObj, ‘M’);
See also rise_dates.dates.
dates
- dates Constructor method to create a dates object.
obj = dates(year, month, day, frequency, incr) creates a dates object with the specified year, month, day, frequency, and increment.
Arguments: - year: The year value of the dates. - month: The month value of the dates. - day: The day value of the dates. - frequency: The frequency of the dates (e.g., ‘D’ for daily, ‘M’ for monthly). - incr: The increment value for the dates.
datestr
DATESTR Convert date objects to formatted date strings.
s = datestr(obj) converts the date objects in the input array obj to formatted date strings using the default format based on the frequency of the dates. The formatted date strings are returned as a character array.
s = datestr(obj, format) converts the date objects to formatted date strings using the specified format. The format can be a character vector or a string.
Inputs:
obj: Array of date objects.
format: Format for the date strings (optional). If not provided, the default format based on the frequency of the dates is used.
Output:
s: Character array of formatted date strings.
Examples:
daily dates
d=rd(1990,1,25):rd(1990,6,25); disp(datestr(d))
weekly dates
w=rw(1990,1):rw(1990,53); disp(datestr(w))
monthly dates
m=rm(1990,1):rm(1990,12); disp(datestr(m))
quarterly dates
q=rq(1990,1):rq(1990,4); disp(datestr(q))
half-yearly dates
h=rh(1990,1):rh(1995,2); disp(datestr(h))
yearly dates
y=ry(1990):ry(1995); disp(datestr(y))
annual dates
a=ra(1990):ra(1995); disp(datestr(a))
double
DOUBLE returns the serial number representation of the date object.
Returns:
serial: The serial number representation of the date object.
Example:
dateObj = daily(2023, 5, 17); serialNum = double(dateObj); disp(serialNum) % 737988
See also datenum.
fill
FILL Overloaded fill for rise_dates.dates objects.
Converts any rise_dates.dates argument to its underlying datetime values before delegating to MATLAB’s fill. This keeps filled patches aligned with a datetime axis (e.g. one set up by a prior ts.plot) and avoids the datenum-on-datetime-axis trap that misplaces patches into the wrong year.
Syntax:
fill(X, Y, C) fill(..., Name, Value) h = fill(...)Example:
xstart = rq(1990,1); db = ts(xstart, log((1:100).')); plot(db) hold on yl = ylim; rs = rq(1996,3); re = rq(2009,4); fill([rs re re rs], [yl(1) yl(1) yl(2) yl(2)], ... [0.9 0.9 0.9], 'EdgeColor','none','FaceAlpha',0.3);See also FILL, plot.
intersect
intersect returns the intersection of two date objects.
- Usage:
[C, IA, IB] = intersect(A, B)
- Inputs:
A: First date object of class ‘rise_dates.dates’.
B: Second date object of class ‘rise_dates.dates’.
- Outputs:
C: Date object representing the intersection of A and B.
IA: Indices of the common elements in A.
IB: Indices of the common elements in B.
- Example:
A = DailyDate(2023, 1, 1:10); B = DailyDate(2023, 5, 1:10); [C, IA, IB] = intersect(A, B);
See also rise_dates.dates
ismember
ISMEMBER Determine which elements of a dates object are in another dates object.
[LIA, LOCB] = ismember(A, B) returns logical arrays LIA and LOCB, where LIA contains true for the elements in A that are also in B, and LOCB contains the indices of the corresponding elements in B. The input A can be either a character vector representing a date or a rise_dates.dates object. B must be a rise_dates.dates object.
- Inputs:
A: The input dates to check for membership. It can be either a character vector representing a date or a rise_dates.dates object.
B: The dates object to search for membership.
- Outputs:
LIA: Logical array of the same size as A, containing true for the elements in A that are also in B, and false otherwise.
LOCB: Array of the same size as A, containing the indices of the corresponding elements in B. If an element in A is not found in B, the corresponding element in LOCB is set to 0.
- Example:
datesA = rd(‘2023-06-18’):rd(‘2023-06-20’); % Daily dates datesB = rd(‘2023-06-19’):rd(‘2023-06-22’); % Daily dates [LIA, LOCB] = datesA.ismember(datesB);
- Notes:
If A is a character vector representing a date, it is converted to a rise_dates.dates object using the date2serial function.
The function checks for membership based on the frequency of the dates objects. If the frequencies do not match, the function returns empty arrays.
The tolerance (Tol) for comparing dates is set to 1e-3. If the frequencies of the dates objects are ‘M’, ‘Q’, ‘H’, or ‘Y’, the tolerance is increased by 1.
The function compares the elements of A with B and returns true for elements that are within the tolerance of B. LOCB contains the indices of the corresponding elements in B. If an element in A is not found in B, the corresponding element in LOCB is set to 0.
See also
rise_dates.dates, date2serial
max
MAX Find the maximum date among two dates or a vector of dates.
MAX(DATE1, DATE2) returns the maximum date between DATE1 and DATE2.
MAX(DATES) returns the maximum date from the vector of dates DATES.
Input arguments:
DATE1, DATE2: Date objects to compare.
DATES: Vector of date objects.
Output argument:
MAXDATE: Maximum date among the inputs.
min
MIN Find the minimum date among two dates or a vector of dates.
MIN(DATE1, DATE2) returns the minimum date between DATE1 and DATE2.
MIN(DATES) returns the minimum date from the vector of dates DATES.
Input arguments:
DATE1, DATE2: Date objects to compare.
DATES: Vector of date objects.
Output argument:
MINDATE: Minimum date among the inputs.
minus
MINUS - Subtracts a specified number of periods to the date object.
Syntax:
newObj = obj-decrement
Input Arguments:
obj: The date object of the rise_dates.dates class.
decrement: The number of periods to subtract to the date object. It can be a numeric value (integer) or another rise_dates.dates object.
Output Argument:
newObj: The new date object after subtracting the specified number of periods. If decrement is a rise_dates.dates object, the output is the difference of the date numbers.
Example:
newDateObj = obj+3;
See also
rise_dates.dates
plus
plus - Adds a specified number of periods to the date object.
Syntax:
newObj = plus(obj, increment)
Input Arguments:
obj: The date object of the rise_dates.dates class.
increment: The number of periods to add to the date object. It can be a numeric value (integer) or another rise_dates.dates object.
Output Argument:
newObj: The new date object after adding the specified number of periods. If increment is a rise_dates.dates object, the output is the sum of the date numbers.
Example:
newDateObj = obj+3;
See also
rise_dates.dates
unique
UNIQUE Find unique elements in an array of dates.
[C, IA, IC] = unique(obj) returns the unique elements of the input date array obj. The output C contains the sorted unique values of obj. The output IA is an index vector such that C = obj(IA). The output IC is an index vector that specifies the index of each value of obj in the sorted list C. If obj is an array of date objects, the uniqueness is determined based on the date values stored in the objects. If obj is a numeric or character array, the uniqueness is determined based on the values in obj itself.
[C, IA, IC] = unique(obj, varargin) allows additional optional arguments to be passed to the unique function, See the unique function for “double”.
Inputs:
obj: Array of dates or numeric/character array.
varargin (optional): Additional arguments for the unique function.
Outputs:
C: Sorted array of unique values from obj.
IA: Index vector such that C = obj(IA).
IC: Index vector that specifies the index of each value of obj in the sorted list C.
Examples: - Unique dates from a date array: d1 = rm(1990,1):rm(1995,12); d2 = rm(1992,1):rm(1998,12); [C, IA, IC] = unique([d1,d2]) assert(isequal(C,rm(1990,1):rm(1998,12)))
xlim
XLIM Overloaded xlim for rise_dates.dates objects.
This function allows xlim to accept rise_date objects directly by converting them to MATLAB datenum values.
- Example:
xlim(rq(1995, 1), rq(2000, 4));
xline
xline overloads xline for the rise_dates.dates class. It creates vertical lines at specified x-values. It is typically used to mark important dates or events on plots.
Syntax:
xline(VALUES) xline(VALUES, LINESPEC) xline(VALUES, LINESPEC, LABELS) xline(…Name,Value) XL = xline(…)
Arguments:
values: A scalar or a vector of date values where the vertical lines will be placed.
LINESPEC: line style, color, or both. For example, ‘:’ creates a dotted line, ‘r’ creates a red line, and ‘r:’ creates a dotted, red line.
LABELS: When VALUES contains multiple elements, you can display different labels for each line by specifying LABELS as either cell array of character vectors or a string array with the same number of elements as VALUES. Alternatively, specify LABELS as a character vector or a string scalar to display the same label on all the lines.
Example 1:
xstart=rq(1990,1); db=ts(xstart,log((1:100).')); plot(db) xline([rq(1996,3),rq(2009,4)])Example 2:
xline([rq(1996,3),rq(2009,4)], 'r--', {'Holiday', 'Event'})Note : for more explanations, see Matlab’s xline.
ymd
ymd - Extracts the year, month, and day components from the dates.
- Syntax:
[Y, M, D] = ymd(this)
- Input Arguments:
this: An object of the rise_dates.dates class or its derived classes representing a collection of dates.
- Output Arguments:
Y: Numeric array of years.
M: Numeric array of months.
D: Numeric array of days.
- Example:
[Y, M, D] = ymd(dateObj)
See also
rise_dates.dates