| 1 |
function [Myrqm,nMyrqm] = fn_calyrqm(q_m,Byrqm,Eyrqm) |
| 2 |
% [Myrqm,nMyrqm] = fn_calyrqm(q_m,Byrqm,Eyrqm) |
| 3 |
% |
| 4 |
% Given the beginning and end years and quarters (months), export a matrix of all years and |
| 5 |
% quarters (months) for these years and in between |
| 6 |
% |
| 7 |
% q_m: 4 if quarterly and 12 if monthly |
| 8 |
% Byrqm: [year quarter(month)] -- all integers, the begining year and quarter (month) |
| 9 |
% Eyrqm: [year quarter(month)] -- all integers, the end year and quarter (month) |
| 10 |
%------------------- |
| 11 |
% Myrqm: matrix of all years and quarters (months) between and incl. Byrqm and Eyrqm |
| 12 |
% nMyrqm: number of data points incl. Byrqm and Eyrqm |
| 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 ~isempty(find(Byrqm-round(Byrqm))) | (q_m-round(q_m)) | ~isempty(find(Byrqm-round(Byrqm))) |
| 34 |
error('argin qm, Byrqm, or Eyrqm must of integer') |
| 35 |
elseif Byrqm(1)>Eyrqm(1) |
| 36 |
error('Eyrqm(1) must be equal to or greater than Byrqm(1)') |
| 37 |
elseif Byrqm(1)==Eyrqm(1) |
| 38 |
if Byrqm(2)>Eyrqm(2) |
| 39 |
error('Eyrqm(2) must be equal to or greater than Byrqm(2) because of the same year') |
| 40 |
end |
| 41 |
end |
| 42 |
|
| 43 |
|
| 44 |
Yr = Byrqm(1)+[0:Eyrqm(1)-Byrqm(1)]'; |
| 45 |
|
| 46 |
if length(Yr)>=2 % there are years and quarters (months) between Byrqm and Eyrqm |
| 47 |
n=length(Yr)-2; |
| 48 |
C=zeros(n*q_m,2); |
| 49 |
C(:,1) = kron(Yr(2:end-1),ones(q_m,1)); |
| 50 |
C(:,2) = kron(ones(n,1),[1:q_m]'); |
| 51 |
|
| 52 |
%* initialize a matrix of years and quarters (months) including Byrqm and Eyrqm |
| 53 |
Myrqm = zeros((q_m-Byrqm(2)+1)+Eyrqm(2)+n*q_m,2); |
| 54 |
|
| 55 |
%* Years in between |
| 56 |
n1=q_m-Byrqm(2)+1; |
| 57 |
n2=Eyrqm(2); |
| 58 |
Myrqm(n1+1:end-n2,:) = C; |
| 59 |
%* Beginning year |
| 60 |
for k=1:n1 |
| 61 |
Myrqm(k,:) = [Byrqm(1) Byrqm(2)+k-1]; |
| 62 |
end |
| 63 |
%* End year |
| 64 |
for k=1:n2 |
| 65 |
Myrqm(end-Eyrqm(2)+k,:) = [Eyrqm(1) k]; |
| 66 |
end |
| 67 |
else %* all the data are in the same calendar year |
| 68 |
n1=Eyrqm(2)-Byrqm(2)+1; |
| 69 |
Myrqm = zeros(n1,2); |
| 70 |
for k=1:n1 |
| 71 |
Myrqm(k,:) = [Byrqm(1) Byrqm(2)+k-1]; |
| 72 |
end |
| 73 |
end |
| 74 |
|
| 75 |
nMyrqm = size(Myrqm,1); |