如何识别与非工作日对应的日期数字,并在MATLAB中的下一个可用工作日更换它们 [英] How to identify date numbers corresponding to non-business days and replace them with by the next available business day in MATLAB
问题描述
示例:
datenumbers = [736062; 736063; 736064; 736065; 736066; 736067]
%对应于[wed,thu,fri,sat,sun,mon]
这包含 [736065; 736066]
对应于即将到来的周末。因为这些不工作日,我想确定对应于下一个星期一的日期数字,并更改两个条目,以便:
datenumbers = [736062; 736063; 736064; 736067; 736067; 736067]
%对应于[wed,thu,fri,mon,mon,mon]
一种方法是循环使用所有的值,如果是星期六或星期日,则更改它们。 >
datenumbers = [736062; 736063; 736064; 736065; 736066; 736067];
for i = 1:length(datenumbers)
weekDay = mod(datenumbers(i),7);
如果weekDay == 1 || weekDay == 2
datenumbers(i)=(3-weekDay)+ datenumbers(i);
end
end
I am working with time series data in MATLAB. I have got two vectors of date numbers, one of which relies on a somewhat subjective data source. If both vectors were perfectly accurate, all date numbers should correspond to trading days while one vector would be a 'proper subset' of the other. Unfortunately this is not the case because one of the vectors contains several date numbers which correspond to non-business days. I would like to find a way to replace all non-business days in this vector with the next available business day.
Example:
datenumbers = [736062;736063;736064;736065;736066;736067]
% corresponds to [wed, thu, fri, sat, sun, mon]
This contains [736065;736066]
which corresponds to the upcoming weekend. Because these are not working days I would like to identify the date number corresponding to the subsequent monday and change both entries so that:
datenumbers = [736062;736063;736064;736067;736067;736067]
% corresponds to [wed, thu, fri, mon, mon, mon]
One way to do it is simply to loop through all your values and change them if they are Saturday or Sunday.
datenumbers = [736062;736063;736064;736065;736066;736067];
for i = 1:length(datenumbers)
weekDay = mod(datenumbers(i),7);
if weekDay == 1 || weekDay == 2
datenumbers(i) = (3-weekDay) + datenumbers(i);
end
end
这篇关于如何识别与非工作日对应的日期数字,并在MATLAB中的下一个可用工作日更换它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!