-
Notifications
You must be signed in to change notification settings - Fork 1
/
weeks_new.m
executable file
·65 lines (61 loc) · 1.64 KB
/
weeks_new.m
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function [month, day] = weeks_new(year,week,varargin)
%WEEKS return the month and the day when the requested weeks begins
% The year is not needed as it refers always to weeks in the given year
% [ M, D ] = weeks(Y, W)
%
% Example:
%
% [ M, D ] = weeks(2000, 52)
%
%
% BITS - Banca d'Italia Time Series
% Copyright 2005-2012 Banca d'Italia - Area Ricerca Economica e Relazioni Internazionali
%
% Author: Emmanuele Somma (emmanuele_DOT_somma_AT_bancaditalia_DOT_it)
% Area Ricerca Economica e Relazioni Internazionali
% Banca d'Italia
%
% Default start of the week is on Sunday
whichday=1;
if nargin==3
strday=varargin{1};
switch strday
case 'Sun'
whichday=1;
case 'Mon'
whichday=2;
case 'Tue'
whichday=3;
case 'Wed'
whichday=4;
case 'Thu'
whichday=5;
case 'Fri'
whichday=6;
case 'Sat'
whichday=7;
otherwise
error('Input for day of week must be 3 letters acronym')
end
end
if or( week < 0, week > 53 )
error([ mfilename '::WeekIndexOutsideRange'])
end
if calendar_isleap(year)==0 && week == 53
error([ mfilename '::WeekIndexOutsideRangeOnNonLeapYear'])
end
start_week = [];
for m=1:12
a = calendar(year,m);
start_week = [ start_week ; a(:,whichday) ];
end
n = 0;
i = 0;
while n < week
i = i + 1;
day = start_week(i);
if day ~= 0
n = n + 1;
end
end
month = fix((i-1)/6)+1;