【发布时间】:2014-07-22 10:58:18
【问题描述】:
我正在尝试创建一个包含每日日期的向量。但是,我不想包括周末(即星期六或星期日。
我正在使用 isbusday 功能,它几乎可以满足我的要求。因为在我的 date_vector('date_vec')中没有返回星期六或星期日。然而,它也删除了美国银行假期,例如在我的日期向量中没有 12 月 25 日。有没有办法强制这种方法忽略银行假期,还是我应该完全使用另一种方法?
date_vec = [dt_start : dt_end]; % daily dates
weekend_vec = [1 0 0 0 0 0 1]; % vector to help remove weekends
bus_day = isbusday(date_vec, [], weekend_vec);
date_vec(bus_day == 0) = [];
Matlab 函数 ISBUSDAY
%ISBUSDAY True for dates that are business days.
%
% T = ISBUSDAY(Date, Holiday, Weekend)
%
% Inputs:
%
% Date - a vector of dates in question. Dates are assumed to be whole
% date numbers or date stamps with no fractional or time
% values.
%
% Optional Inputs:
%
% Holiday - a user-defined vector of holidays. The default
% is a predefined US holidays (in holidays.m)
%
% Weekend - a vector of length 7, containing 0 and 1, with
% the value of 1 to indicate weekend day(s).
% The first element of this vector corresponds
% to Sunday.
% Thus, when Saturday and Sunday are weekend
% then WEEKEND = [1 0 0 0 0 0 1]. The default
% is Saturday and Sunday weekend.
【问题讨论】:
-
请发布一个可运行的例子:define
dt_startetc -
试试
mod(date_vec, 7),你会发现它会为一周中的每一天分配一个唯一的数字(0-6)。然后你可以像过滤数字一样过滤周末。 -
工作日功能可以工作吗? mathworks.se/help/matlab/ref/weekday.html 类似 ismember(weekday(date_vec), 2:6)