Home > matlab > @dynSeries > horzcat.m

horzcat

PURPOSE ^

@info:

SYNOPSIS ^

function a = horzcat(varargin)

DESCRIPTION ^

@info:
! @deftypefn {Function file} {@var{a} =} horzcat (@var{b},@var{c}, ...)
! @anchor{horzcat}
! @sp 1
! Method of the dynSeries class.
! @sp 1
! Merge Dynare time series objects. This method overloads the horizontal concatenation operator, so that
! two (or more) time series objects can be merged using the following syntax:
!
!     a = [b, c, d];
! @sp 2
! @strong{Inputs}
! @sp 1
! @table @ @var
! @item b
! Dynare time series object, instantiated by @ref{dynSeries}.
! @item c
! Dynare time series object, instantiated by @ref{dynSeries}.
! @end table
! @sp 2
! @strong{Outputs}
! @sp 1
! @table @var
! @item a
! Dynare time series object.
! @end table
! @sp 2
! @strong{This function is called by:}
! @ref{descriptive_statistics}
!
! @strong{This function calls:}
! @ref{dynSeries}, @ref{private/horzcat2}
!
! @strong{Remark 1.} It is assumed that the two time series objects have the same frequencies. The two time series objects can cover
! different time ranges.
!
! @end deftypefn
@eod:

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function a = horzcat(varargin)
0002 
0003 %@info:
0004 %! @deftypefn {Function file} {@var{a} =} horzcat (@var{b},@var{c}, ...)
0005 %! @anchor{horzcat}
0006 %! @sp 1
0007 %! Method of the dynSeries class.
0008 %! @sp 1
0009 %! Merge Dynare time series objects. This method overloads the horizontal concatenation operator, so that
0010 %! two (or more) time series objects can be merged using the following syntax:
0011 %!
0012 %!     a = [b, c, d];
0013 %! @sp 2
0014 %! @strong{Inputs}
0015 %! @sp 1
0016 %! @table @ @var
0017 %! @item b
0018 %! Dynare time series object, instantiated by @ref{dynSeries}.
0019 %! @item c
0020 %! Dynare time series object, instantiated by @ref{dynSeries}.
0021 %! @end table
0022 %! @sp 2
0023 %! @strong{Outputs}
0024 %! @sp 1
0025 %! @table @var
0026 %! @item a
0027 %! Dynare time series object.
0028 %! @end table
0029 %! @sp 2
0030 %! @strong{This function is called by:}
0031 %! @ref{descriptive_statistics}
0032 %!
0033 %! @strong{This function calls:}
0034 %! @ref{dynSeries}, @ref{private/horzcat2}
0035 %!
0036 %! @strong{Remark 1.} It is assumed that the two time series objects have the same frequencies. The two time series objects can cover
0037 %! different time ranges.
0038 %!
0039 %! @end deftypefn
0040 %@eod:
0041 
0042 % Copyright (C) 2011 Dynare Team
0043 % stephane DOT adjemian AT univ DASH lemans DOT fr
0044 %
0045 % This file is part of Dynare.
0046 %
0047 % Dynare is free software: you can redistribute it and/or modify
0048 % it under the terms of the GNU General Public License as published by
0049 % the Free Software Foundation, either version 3 of the License, or
0050 % (at your option) any later version.
0051 %
0052 % Dynare is distributed in the hope that it will be useful,
0053 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0054 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0055 % GNU General Public License for more details.
0056 %
0057 % You should have received a copy of the GNU General Public License
0058 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0059 
0060 if nargin==0 || nargin==1
0061     error('dynSeries::horzcat: I need at least two input arguments!')
0062 end
0063 
0064 if nargin==2
0065     a = horzcat2(varargin{1},varargin{2});
0066 else
0067     a = horzcat2(varargin{1},varargin{2});
0068     for i=3:nargin
0069         a = horzcat2(a,varargin{i});
0070     end
0071 end
0072 
0073 %@test:1
0074 %$ addpath ../matlab
0075 %$ % Define a data set.
0076 %$ A = [transpose(1:10),2*transpose(1:10)];
0077 %$ B = [transpose(1:10),2*transpose(1:10)];
0078 %$
0079 %$ % Define names
0080 %$ A_name = char('A1','A2');
0081 %$ B_name = char('B1','B2');
0082 %$
0083 %$ % Define expected results.
0084 %$ e.time = [transpose(1:10), ones(10,1)];
0085 %$ e.freq = 1;
0086 %$ e.name = char('A1','A2','B1','B2');
0087 %$ e.data = [A,B];
0088 %$
0089 %$ % Instantiate two time series objects.
0090 %$ ts1 = dynSeries(A,[],A_name,[]);
0091 %$ ts2 = dynSeries(B,[],B_name,[]);
0092 %$
0093 %$ % Call the tested method.
0094 %$ ts3 = [ts1,ts2];
0095 %$
0096 %$ % Check the results.
0097 %$
0098 %$ t(1) = dyn_assert(ts3.Time.time,e.time);
0099 %$ t(2) = dyn_assert(ts3.freq,e.freq);
0100 %$ t(3) = dyn_assert(ts3.data,e.data);
0101 %$ t(4) = dyn_assert(ts3.name,e.name);
0102 %$ T = all(t);
0103 %@eof:1
0104 
0105 %@test:2
0106 %$ addpath ../matlab
0107 %$ % Define a data set.
0108 %$ A = [transpose(1:10),2*transpose(1:10)];
0109 %$ B = [transpose(5:12),2*transpose(5:12)];
0110 %$
0111 %$ % Define names
0112 %$ A_name = char('A1','A2');
0113 %$ B_name = char('B1','B2');
0114 %$
0115 %$ % Define initial date
0116 %$ A_init = 2001;
0117 %$ B_init = 2005;
0118 %$
0119 %$ % Define expected results.
0120 %$ e.time = [transpose(2000+(1:12)), ones(12,1)];
0121 %$ e.freq = 1;
0122 %$ e.name = char('A1','A2','B1','B2');
0123 %$ e.data = [ [A; NaN(2,2)], [NaN(4,2); B]];
0124 %$
0125 %$ % Instantiate two time series objects.
0126 %$ ts1 = dynSeries(A,A_init,A_name,[]);
0127 %$ ts2 = dynSeries(B,B_init,B_name,[]);
0128 %$
0129 %$ % Call the tested method.
0130 %$ ts3 = [ts1,ts2];
0131 %$
0132 %$ % Check the results.
0133 %$ t(1) = dyn_assert(ts3.Time.time,e.time);
0134 %$ t(2) = dyn_assert(ts3.freq,e.freq);
0135 %$ t(3) = dyn_assert(ts3.data,e.data);
0136 %$ t(4) = dyn_assert(ts3.name,e.name);
0137 %$ T = all(t);
0138 %@eof:2
0139 
0140 %@test:3
0141 %$ addpath ../matlab
0142 %$ % Define a data set.
0143 %$ A = [transpose(1:7),2*transpose(1:7)];
0144 %$ B = [transpose(5:11),2*transpose(5:11)];
0145 %$
0146 %$ % Define names
0147 %$ A_name = char('A1','A2');
0148 %$ B_name = char('B1','B2');
0149 %$
0150 %$ % Define initial date
0151 %$ A_init = '1950Q1';
0152 %$ B_init = '1950Q3';
0153 %$
0154 %$ % Define expected results.
0155 %$ e.time = [ 1950, 1; 1950, 2; 1950, 3; 1950, 4; 1951, 1; 1951, 2; 1951, 3; 1951, 4; 1952, 1];
0156 %$ e.freq = 4;
0157 %$ e.name = char('A1','A2','B1','B2');
0158 %$ e.data = [ [A; NaN(2,2)], [NaN(2,2); B]];
0159 %$
0160 %$ % Instantiate two time series objects.
0161 %$ ts1 = dynSeries(A,A_init,A_name,[]);
0162 %$ ts2 = dynSeries(B,B_init,B_name,[]);
0163 %$
0164 %$ % Call the tested method.
0165 %$ ts3 = [ts1,ts2];
0166 %$
0167 %$ % Check the results.
0168 %$ t(1) = dyn_assert(ts3.Time.time,e.time);
0169 %$ t(2) = dyn_assert(ts3.freq,e.freq);
0170 %$ t(3) = dyn_assert(ts3.data,e.data);
0171 %$ t(4) = dyn_assert(ts3.name,e.name);
0172 %$ T = all(t);
0173 %@eof:3
0174 
0175 %@test:4
0176 %$ addpath ../matlab
0177 %$ % Define a data set.
0178 %$ A = [transpose(1:7),2*transpose(1:7)];
0179 %$ B = [transpose(5:9),2*transpose(5:9)];
0180 %$
0181 %$ % Define names
0182 %$ A_name = char('A1','A2');
0183 %$ B_name = char('B1','B2');
0184 %$
0185 %$ % Define initial date
0186 %$ A_init = '1950Q1';
0187 %$ B_init = '1950Q3';
0188 %$
0189 %$ % Define expected results.
0190 %$ e.time = [ 1950, 1; 1950, 2; 1950, 3; 1950, 4; 1951, 1; 1951, 2; 1951, 3];
0191 %$ e.freq = 4;
0192 %$ e.name = char('A1','A2','B1','B2');
0193 %$ e.data = [ A, [NaN(2,2); B]];
0194 %$
0195 %$ % Instantiate two time series objects.
0196 %$ ts1 = dynSeries(A,A_init,A_name,[]);
0197 %$ ts2 = dynSeries(B,B_init,B_name,[]);
0198 %$
0199 %$ % Call the tested method.
0200 %$ ts3 = [ts1,ts2];
0201 %$
0202 %$ % Check the results.
0203 %$ t(1) = dyn_assert(ts3.Time.time,e.time);
0204 %$ t(2) = dyn_assert(ts3.freq,e.freq);
0205 %$ t(3) = dyn_assert(ts3.data,e.data);
0206 %$ t(4) = dyn_assert(ts3.name,e.name);
0207 %$ T = all(t);
0208 %@eof:4
0209 
0210 %@test:5
0211 %$ addpath ../matlab
0212 %$ % Define a data set.
0213 %$ A = [transpose(1:10),2*transpose(1:10)];
0214 %$ B = [transpose(1:10),3*transpose(1:10)];
0215 %$ C = [transpose(1:10),4*transpose(1:10)];
0216 %$
0217 %$ % Define names
0218 %$ A_name = char('A1','A2');
0219 %$ B_name = char('B1','B2');
0220 %$ C_name = char('C1','C2');
0221 %$
0222 %$ % Define expected results.
0223 %$ e.time = [transpose(1:10), ones(10,1)];
0224 %$ e.freq = 1;
0225 %$ e.name = char('A1','A2','B1','B2','C1','C2');
0226 %$ e.data = [A,B,C];
0227 %$
0228 %$ % Instantiate two time series objects.
0229 %$ ts1 = dynSeries(A,[],A_name,[]);
0230 %$ ts2 = dynSeries(B,[],B_name,[]);
0231 %$ ts3 = dynSeries(C,[],C_name,[]);
0232 %$
0233 %$ % Call the tested method.
0234 %$ ts4 = [ts1,ts2,ts3];
0235 %$
0236 %$ % Check the results.
0237 %$ t(1) = dyn_assert(ts4.Time.time,e.time);
0238 %$ t(2) = dyn_assert(ts4.freq,e.freq);
0239 %$ t(3) = dyn_assert(ts4.data,e.data);
0240 %$ t(4) = dyn_assert(ts4.name,e.name);
0241 %$ T = all(t);
0242 %@eof:5

Generated on Fri 18-May-2012 02:41:00 by m2html © 2005