| 1 |
function dummyout = qplot2(datavector,inityear,initquart,quarter_label) |
| 2 |
%QPLOT Quarterly data plot |
| 3 |
%QPLOT(DATA,YEAR,QUARTER,LABEL) plots quarterly data against years |
| 4 |
%and quarters begining with YEAR:QUARTER. Quarters are not labeled if |
| 5 |
%LABEL=0. |
| 6 |
% |
| 7 |
%e.g. if GDP is a vector containing quarterly observations |
| 8 |
%on gdp beginning in the third quarter of 1985, the command |
| 9 |
%QPLOT(GDP,85,3) plots the observations against years and quarters. |
| 10 |
%You may specify the year as 85 or 1985 but using 85 looks better. |
| 11 |
% |
| 12 |
%Setting LABEL to the values 5 or 10 will cause only every fifth |
| 13 |
%or every tenth year to be labeled beginning with the first decade |
| 14 |
%after YEAR. |
| 15 |
|
| 16 |
% QPLOT was written by Clark A. Burdick of the research |
| 17 |
% department of the Federal Reserve Bank of Atlanta. |
| 18 |
% Original: June 18, 1997 |
| 19 |
% Last Modified: July 23, 1997 |
| 20 |
|
| 21 |
% |
| 22 |
% Copyright (C) 1997-2012 Clark A. Burdick |
| 23 |
% |
| 24 |
% This free software: you can redistribute it and/or modify |
| 25 |
% it under the terms of the GNU General Public License as published by |
| 26 |
% the Free Software Foundation, either version 3 of the License, or |
| 27 |
% (at your option) any later version. |
| 28 |
% |
| 29 |
% It is distributed in the hope that it will be useful, |
| 30 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 31 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 32 |
% GNU General Public License for more details. |
| 33 |
% |
| 34 |
% If you did not received a copy of the GNU General Public License |
| 35 |
% with this software, see <http://www.gnu.org/licenses/>. |
| 36 |
% |
| 37 |
|
| 38 |
|
| 39 |
% TO BE DONE: |
| 40 |
% 1. Add better bullet proofing |
| 41 |
% 2. Cleaning and streamlining |
| 42 |
% 3. Better string manipulation |
| 43 |
% 4. Options for XTick |
| 44 |
|
| 45 |
|
| 46 |
if nargin == 1 |
| 47 |
warning('Proper usage is QPLOT(data,year,quarter,label') |
| 48 |
inityear = input('What is the initial year? '); |
| 49 |
initquart = input('What is the initial quarter? '); |
| 50 |
quarter_label = input('Enter 1 for labeled quarters, 0 for unlableled quarters: '); |
| 51 |
end |
| 52 |
|
| 53 |
if nargin == 3 |
| 54 |
quarter_label = 1; |
| 55 |
end |
| 56 |
|
| 57 |
nquart = length(datavector); |
| 58 |
nyear = ceil(nquart/4); |
| 59 |
|
| 60 |
years = inityear + [0:nyear]; |
| 61 |
if quarter_label == 5 |
| 62 |
years = years.*[round(years/5) == years/5]; |
| 63 |
end |
| 64 |
if quarter_label == 10 |
| 65 |
years = years.*[round(years/10) == years/10]; |
| 66 |
end |
| 67 |
|
| 68 |
xtickvec = (kron(years,[1 0 0 0])+kron(ones(1,nyear+1),[0 2 3 4]))'; |
| 69 |
|
| 70 |
if quarter_label ~= 1 |
| 71 |
xtickvec = num2str(xtickvec); |
| 72 |
xtickvec = strrep(xtickvec,{' 0'},{' '}); |
| 73 |
xtickvec = strrep(xtickvec,{' 2'},{' '}); |
| 74 |
xtickvec = strrep(xtickvec,{' 3'},{' '}); |
| 75 |
xtickvec = strrep(xtickvec,{' 4'},{' '}); |
| 76 |
end |
| 77 |
|
| 78 |
|
| 79 |
plot(datavector); |
| 80 |
set(gca,'XTick',[1:nquart]); |
| 81 |
set(gca,'XTickLabel',xtickvec(initquart:initquart+(nquart-1))); |