1function scaleout = fn_multigraph2(imf1,imf2,...
2                         nrow,ncol,nstp,xlab,ylab,XTick,YTickIndx,scaleIndx)
3%Stacking two sets of impulse responses in one graph.  See fn_multigraph1.m.
4%imf1, imf2 -- each has 3 dimensions.  Row: horizon; column: 'nrow' variables; 3rd dim: 'ncol' situations such as regimes 1 and 2.
5%   imf: row: "nstp" time horizon (in the graphics), column: "nrow "variables (row in
6%             the graphics), 3rd D: across "ncol" different situations (column in
7%             the graphics)
8%   nrow:  # of rows for the graphics
9%   ncol:  # of columns for the graphics
10%   YTickIndx:  1: enable YTick; 0: disable
11%   scaleIndx:  1: enable scale along Y-axis; 0: disable
12%
13%  See imrgraph, imcerrgraph, imrerrgraph
14%
15% Copyright (C) 1997-2012 Tao Zha
16%
17% This free software: you can redistribute it and/or modify
18% it under the terms of the GNU General Public License as published by
19% the Free Software Foundation, either version 3 of the License, or
20% (at your option) any later version.
21%
22% It is distributed in the hope that it will be useful,
23% but WITHOUT ANY WARRANTY; without even the implied warranty of
24% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25% GNU General Public License for more details.
26%
27% If you did not received a copy of the GNU General Public License
28% with this software, see <http://www.gnu.org/licenses/>.
29%
30
31t = 1:nstp;
32nrow
33ncol
34
35temp1=zeros(ncol,1);
36temp2=zeros(ncol,1);
37maxval=zeros(nrow,1);
38minval=zeros(nrow,1);
39for i = 1:nrow
40   for j = 1:ncol
41      %jnk1=max(firsth(:,i,j));
42      %jnk2=max(firstl(:,i,j));
43      %jnk3=max(firsth1(:,i,j));
44      jnk4=max(imf2(:,i,j));
45      jnk5=max(imf1(:,i,j));
46
47      temp1(j)=max([jnk4 jnk5]);
48      %
49      %jnk1=min(firstl(:,i,j));
50      %jnk2=min(firsth(:,i,j));
51      %jnk3=min(firstl1(:,i,j));
52      jnk4=min(imf2(:,i,j));
53      jnk5=min(imf1(:,i,j));
54
55      temp2(j)=min([jnk4 jnk5]);
56	end
57   maxval(i)=max(temp1);
58   minval(i)=min(temp2);
59end
60
61scaleout = [maxval(:) minval(:)];
62
63%--------------
64%  Column j: Shock 1 to N; Row i: Responses to
65%-------------
66figure
67rowlabel = 1;
68for i = 1:nrow      % column: from top to bottom
69   columnlabel = 1;
70
71   if minval(i)<0
72      if maxval(i)<=0
73         yt=[minval(i) 0];
74		else
75         yt=[minval(i) 0 maxval(i)];
76		end
77   else % (minval(i) >=0)
78      if maxval(i) > 0
79         yt=[0 maxval(i)];
80		else % (identically zero responses)
81			yt=[-1 0 1];
82		end
83	end
84
85
86   scale=[1 nstp minval(i) maxval(i)];
87   for j = 1:ncol        % row: from left to right
88      k1=(i-1)*ncol+j;
89      subplot(nrow,ncol,k1)
90      plot(t,imf1(:,i,j),t,imf2(:,i,j),'--')
91                %t,[firstl(:,i,j) firsth(:,i,j)],':');
92      grid;
93      if scaleIndx
94         axis(scale);
95      end
96      %set(gca,'YLim',[minval(i) maxval(i)])
97      %
98		set(gca,'XTick',XTick)
99      if YTickIndx
100         set(gca,'YTick',yt)
101      end
102
103      if i<nrow
104			set(gca,'XTickLabelMode','manual','XTickLabel',[])
105		end
106      %set(gca,'XTickLabel',' ');
107      if j>1
108         set(gca,'YTickLabel',' ');
109      end
110      if rowlabel == 1
111         %title(['x' num2str(j)])
112         %title(eval(['x' num2str(j)]))
113			title(char(xlab(j)))
114      end
115      if columnlabel == 1
116         %ylabel(['x' num2str(i)])
117         %ylabel(eval(['x' num2str(i)]))
118			ylabel(char(ylab(i)))
119      end
120      if i==nrow
121         xlabel('Quarters')
122      end
123      columnlabel = 0;
124   end
125   rowlabel = 0;
126end
127