Home > matlab > @dynSeries > private > horzcat2.m

horzcat2

PURPOSE ^

@info:

SYNOPSIS ^

function a = horzcat2(b,c)

DESCRIPTION ^

@info:
! @deftypefn {Function file} {@var{a} =} horzcat2 (@var{b},@var{c}, ...)
! @anchor{private/horzcat2}
! @sp 1
! Private method of the dynSeries class.
! @sp 1
! Merge two Dynare time series objects. This method overloads the horizontal concatenation operator, so that
! two time series objects can be merged using the following syntax
!
!     a = [b, c];
! @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}
!
! @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 = horzcat2(b,c)
0002 
0003 %@info:
0004 %! @deftypefn {Function file} {@var{a} =} horzcat2 (@var{b},@var{c}, ...)
0005 %! @anchor{private/horzcat2}
0006 %! @sp 1
0007 %! Private method of the dynSeries class.
0008 %! @sp 1
0009 %! Merge two Dynare time series objects. This method overloads the horizontal concatenation operator, so that
0010 %! two time series objects can be merged using the following syntax
0011 %!
0012 %!     a = [b, c];
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}
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 %
0044 % This file is part of Dynare.
0045 %
0046 % Dynare is free software: you can redistribute it and/or modify
0047 % it under the terms of the GNU General Public License as published by
0048 % the Free Software Foundation, either version 3 of the License, or
0049 % (at your option) any later version.
0050 %
0051 % Dynare is distributed in the hope that it will be useful,
0052 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0053 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0054 % GNU General Public License for more details.
0055 %
0056 % You should have received a copy of the GNU General Public License
0057 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0058 
0059 % AUTHOR(S) stephane DOT adjemian AT univ DASH lemans DOT fr
0060 
0061 if ~(isa(b,'dynSeries') && isa(c,'dynSeries'))
0062     error('dynSeries::horzcat: All input arguments have to be Dynare time series objects!')
0063 end
0064 
0065 if b.freq ~= c.freq
0066     error('dynSeries::horzcat: All time series objects must have common frequency!')
0067 else
0068     a = dynSeries();
0069     a.freq = b.freq;
0070 end
0071 
0072 d_nobs_flag = 0;
0073 if b.nobs ~= c.nobs
0074     d_nobs_flag = 1;
0075 else
0076     a.nobs = b.nobs;
0077 end
0078 
0079 d_init_flag = 0;
0080 if ~isequal(b.Time(1),c.Time(1))
0081     d_init_flag = 1;
0082 end
0083 
0084 d_last_flag = 0;
0085 if ~isequal(b.Time(end),c.Time(end))
0086     d_last_flag = 1;
0087 end
0088 
0089 a.vobs = b.vobs+c.vobs;
0090 a.name = char(b.name,c.name);
0091 a.tex  = char(b.tex,c.tex);
0092 
0093 if ~( d_nobs_flag(1) || d_init_flag(1) || d_last_flag(1) )
0094     a.Time = b.Time;
0095     a.data = [b.data,c.data];
0096 else
0097     [JUNK,IB] = setdiff(b.Time(:),c.Time(:),'rows');
0098     [JUNK,IC] = setdiff(c.Time(:),b.Time(:),'rows');
0099     [JUNK,JB,JC] = intersect(b.Time(:),c.Time(:),'rows');
0100     a.Time = a.Time.setTime(sortrows([b.Time(IB); b.Time(JB); c.Time(IC)],[1 2]));
0101     a.nobs = rows(a.Time(:));
0102     a.data = NaN(a.nobs,a.vobs);
0103     [junk,ia,ib] = intersect(a.Time(:),b.Time(:),'rows');
0104     a.data(ia,1:b.vobs) = b.data;
0105     [junk,ia,ic] = intersect(a.Time(:),c.Time(:),'rows');
0106     a.data(ia,b.vobs+(1:c.vobs)) = c.data;
0107 end

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