Debian Codegraph @

contrib/ms-sbvar/TZcode/MatlabFiles/dataext.m

raw
1 function [xdsube,Brow,Erow] = dataext(Byrqm,Eyrqm,xdatae)
2 % xdsube = dataext(Byrqm,Eyrqm,xdatae)
3 %
4 % Extract subset of xdatae, given Byrqm and Eyrqm
5 %
6 % Byrqm: [year quarter(month)]: beginning year and period. If Byqm(2)=0, we get annual data.
7 % Eyrqm: [year period]: end year and period. If Byrqm(2)=0, it must be Eyrqm(2)=0.
8 % xdatae: all data (some of which may be NaN) with the first 2 columns indicating years and periods.
9 %----------
10 % xdsube: subset of xdatae.
11 % Brow: the row number in xdatee that marks the first row of xdsube.
12 % Erow: the row number in xdatee that marks the last row of xdsube.
13 %
14 % Tao Zha, April 2000
15 %
16 % Copyright (C) 1997-2012 Tao Zha
17 %
18 % This free software: you can redistribute it and/or modify
19 % it under the terms of the GNU General Public License as published by
20 % the Free Software Foundation, either version 3 of the License, or
21 % (at your option) any later version.
22 %
23 % It is distributed in the hope that it will be useful,
24 % but WITHOUT ANY WARRANTY; without even the implied warranty of
25 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 % GNU General Public License for more details.
27 %
28 % If you did not received a copy of the GNU General Public License
29 % with this software, see <http://www.gnu.org/licenses/>.
30 %
31
32
33 if (Byrqm(2)==0) & (Eyrqm(2)~=0)
34 error('If annual data, make sure both Byrqm(2) and Eyrqm(2) are zero')
35 end
36
37 Brow = min(find(xdatae(:,1)==Byrqm(1)));
38 if isempty(Brow)
39 error('Byrqm is outside the date range indicated by xdatae(:,1:2)!')
40 end
41 if Byrqm(2)>0
42 nadt=Byrqm(2)-xdatae(Brow,2);
43 if nadt<0
44 error('Byrqm is outside the date range indicated by xdatae(:,1:2)!')
45 end
46 Brow=Brow+nadt;
47 end
48 %
49 Erow = min(find(xdatae(:,1)==Eyrqm(1)));
50 if isempty(Erow)
51 error('Eyrqm is outside the date range indicated by xdatae(:,1:2)!')
52 end
53 if Eyrqm(2)>0
54 nadt2=Eyrqm(2)-xdatae(Erow,2);
55 if nadt<0
56 error('Eyrqm is outside the date range indicated by xdatae(:,1:2)!')
57 end
58 Erow=Erow+nadt2;
59 end
60 %
61 xdsube = xdatae(Brow:Erow,:); % with dates