diff --git a/src/@dseries/align.m b/src/@dseries/align.m index 37eece439fc21b9e1e45bc22f9a89eebd1da5814..e6dd75cd1a9fcc45014edee58d80dbae509b77a2 100644 --- a/src/@dseries/align.m +++ b/src/@dseries/align.m @@ -1,5 +1,5 @@ function [a,b] = align(a, b) % --*-- Unitary tests --*-- - + %@info: %! @deftypefn {Function File} {[@var{a}, @var{b}] =} align (@var{a}, @var{b}) %! @anchor{dseries/align} diff --git a/src/@dseries/baxter_king_filter.m b/src/@dseries/baxter_king_filter.m index 4232b5e51f95517b5de173441924be202cc6eb6a..e36cf28d3cf0554457e53dde239939af6e98bf04 100644 --- a/src/@dseries/baxter_king_filter.m +++ b/src/@dseries/baxter_king_filter.m @@ -3,20 +3,20 @@ function ts = baxter_king_filter(ts, high_frequency, low_frequency, K) % --*-- U % ts = baxter_king_filter(ts, high_frequency, low_frequency, K) % % Implementation of Baxter and King (1999) band pass filter for dseries objects. The code is adapted from -% the one provided by Baxter and King. This filter isolates business cycle fluctuations with a period of length +% the one provided by Baxter and King. This filter isolates business cycle fluctuations with a period of length % ranging between high_frequency to low_frequency (quarters). % -% INPUTS +% INPUTS % o ts dseries object. % o high_frequency positive scalar, period length (default value is 6). % o low_frequency positive scalar, period length (default value is 32). % o K positive scalar integer, truncation parameter (default value is 12). % -% OUTPUTS +% OUTPUTS % o ts dseries object. % -% REMARKS -% This filter use a (symmetric) moving average smoother, so that K observations at the beginning and at the end of the +% REMARKS +% This filter use a (symmetric) moving average smoother, so that K observations at the beginning and at the end of the % sample are lost in the computation of the filter. % Copyright (C) 2013-2015 Dynare Team @@ -57,7 +57,7 @@ if nargin<4 || isempty(K) end end end - + % translate periods into frequencies. hf=2.0*pi/high_frequency; lf=2.0*pi/low_frequency; @@ -88,7 +88,7 @@ tmp = zeros(size(ts.data)); % Filtering step. for t = K+1:nobs(ts)-K - tmp(t,:) = weights'*ts.data(t-K:t+K,:); + tmp(t,:) = weights'*ts.data(t-K:t+K,:); end % Update dseries object. @@ -102,7 +102,7 @@ ts.dates = init:init+(nobs(ts)-1); %$ % Create a dataset. %$ e = .2*randn(200,1); %$ u = randn(200,1); -%$ stochastic_trend = cumsum(e); +%$ stochastic_trend = cumsum(e); %$ deterministic_trend = .1*transpose(1:200); %$ x = zeros(200,1); %$ for i=2:200 diff --git a/src/@dseries/center.m b/src/@dseries/center.m index 7548683eefd0f197ffb94acd952a85a1f0daba5e..bbb75a2132d37cf10ee6815646687acdcbc70fdd 100644 --- a/src/@dseries/center.m +++ b/src/@dseries/center.m @@ -31,7 +31,7 @@ if nargin<2 end if geometric - o = o/mean(o, true); + o = o/mean(o, true); else o = o-mean(o, false); end diff --git a/src/@dseries/cumprod.m b/src/@dseries/cumprod.m index 034d591148173cd0bb924cea7a3e6a6f7c9e83b4..0b8a995d69c4742ee23859db3222f564e7a03ffe 100644 --- a/src/@dseries/cumprod.m +++ b/src/@dseries/cumprod.m @@ -49,23 +49,23 @@ end switch nargin case 1 - % Initialize the output. - B = varargin{1}; - % Perform the cumulated sum - if isequal(idx, 1) - B.data = cumprod(B.data); - else - if common_first_period_witout_nan - B.data(idx:end,:) = cumprod(B.data(idx:end,:)); - else - B.data = cumprodnan(B.data); - end - end - % Change the name of the variables - for i=1:vobs(B) - B.name(i) = {['cumprod(' B.name{i} ')']}; - B.tex(i) = {['\prod_t ' B.tex{i}]}; - end + % Initialize the output. + B = varargin{1}; + % Perform the cumulated sum + if isequal(idx, 1) + B.data = cumprod(B.data); + else + if common_first_period_witout_nan + B.data(idx:end,:) = cumprod(B.data(idx:end,:)); + else + B.data = cumprodnan(B.data); + end + end + % Change the name of the variables + for i=1:vobs(B) + B.name(i) = {['cumprod(' B.name{i} ')']}; + B.tex(i) = {['\prod_t ' B.tex{i}]}; + end case 2 if isdseries(varargin{2}) if ~isequal(vobs(varargin{1}), vobs(varargin{2})) diff --git a/src/@dseries/cumsum.m b/src/@dseries/cumsum.m index 3655c824f2ccde649b31928f5d3a49df3770edbc..ba01fab790bb134b8a6e9c186d6c54117deea089 100644 --- a/src/@dseries/cumsum.m +++ b/src/@dseries/cumsum.m @@ -2,12 +2,12 @@ function B = cumsum(varargin) % --*-- Unitary tests --*-- % Overloads matlab's cumsum function for dseries objects. % -% INPUTS +% INPUTS % o A dseries object [mandatory]. % o d dates object [optional] % o v dseries object with one observation [optional] % -% OUTPUTS +% OUTPUTS % o B dseries object. % Copyright (C) 2013-2016 Dynare Team @@ -48,24 +48,24 @@ else end switch nargin - case 1 - % Initialize the output. - B = varargin{1}; - % Perform the cumulated sum - if isequal(idx, 1) - B.data = cumsum(B.data); - else - if common_first_period_witout_nan - B.data(idx:end,:) = cumsum(B.data(idx:end,:)); - else - B.data = cumsumnan(B.data); - end - end - % Change the name of the variables - for i=1:vobs(B) - B.name(i) = {['cumsum(' B.name{i} ')']}; - B.tex(i) = {['\sum_t ' B.tex{i}]}; - end + case 1 + % Initialize the output. + B = varargin{1}; + % Perform the cumulated sum + if isequal(idx, 1) + B.data = cumsum(B.data); + else + if common_first_period_witout_nan + B.data(idx:end,:) = cumsum(B.data(idx:end,:)); + else + B.data = cumsumnan(B.data); + end + end + % Change the name of the variables + for i=1:vobs(B) + B.name(i) = {['cumsum(' B.name{i} ')']}; + B.tex(i) = {['\sum_t ' B.tex{i}]}; + end case 2 if isdseries(varargin{2}) if ~isequal(vobs(varargin{1}), vobs(varargin{2})) diff --git a/src/@dseries/eq.m b/src/@dseries/eq.m index e60d45e642d7e083d59e6599010348e6b981461a..83c8a0bc6a0d6f266e65fe82226a224c828c5ab1 100644 --- a/src/@dseries/eq.m +++ b/src/@dseries/eq.m @@ -2,15 +2,15 @@ function C = eq(A,B) % --*-- Unitary tests --*-- % Overloads eq (==) operator. % -% INPUTS +% INPUTS % o A dseries object (T periods, N variables). % o B dseries object (T periods, N variables). % -% OUTPUTS -% o C T*N matrix of zeros and ones. Element C(t,n) is nonzero iff observation t of variable n in A and B are equal. +% OUTPUTS +% o C T*N matrix of zeros and ones. Element C(t,n) is nonzero iff observation t of variable n in A and B are equal. % -% REMARKS -% If the number of variables, the number of observations or the frequencies are different in A and B, the function returns a zero scalar. +% REMARKS +% If the number of variables, the number of observations or the frequencies are different in A and B, the function returns a zero scalar. % Copyright (C) 2013 Dynare Team % diff --git a/src/@dseries/exist.m b/src/@dseries/exist.m index e4d5e387f0b9b925fbb8dc402cc6da8f38c48d70..3575af03996edbfc07938997d073dd09e70e6d31 100644 --- a/src/@dseries/exist.m +++ b/src/@dseries/exist.m @@ -2,12 +2,12 @@ function l = exist(o, varname) % --*-- Unitary tests --*-- % Tests if a variable exists in dseries object o. % -% INPUTS +% INPUTS % - o [dseries], dseries object. % - varname [string], name of a variable. % -% OUTPUTS -% - l [logical], equal to 1 (true) iff varname is a variable in dseries object o. +% OUTPUTS +% - l [logical], equal to 1 (true) iff varname is a variable in dseries object o. % Copyright (C) 2014 Dynare Team % diff --git a/src/@dseries/extract.m b/src/@dseries/extract.m index f50899a1ff3f7a701c30e26f67b8710552192722..0900ec69bab2cce006bfccc7e2584f4e4e26be77 100644 --- a/src/@dseries/extract.m +++ b/src/@dseries/extract.m @@ -1,7 +1,7 @@ function A = extract(B,varargin) % --*-- Unitary tests --*-- % Extract some variables from a database. - + % Copyright (C) 2012-2016 Dynare Team % % This file is part of Dynare. @@ -67,8 +67,8 @@ A.data = B.data(:,idVariableName); A.dates = B.dates; A.name = B.name(idVariableName); A.tex = B.tex(idVariableName); - - + + %@test:1 %$ % Define a data set. %$ A = rand(10,24); diff --git a/src/@dseries/firstobservedperiod.m b/src/@dseries/firstobservedperiod.m index 92c1b239056f40aee80e660fc1b9e6a5e4545602..5ef31bfcf5b9ebebac592354b32537d821439475 100644 --- a/src/@dseries/firstobservedperiod.m +++ b/src/@dseries/firstobservedperiod.m @@ -2,10 +2,10 @@ function d = firstobservedperiod(o) % --*-- Unitary tests --*-- % Returns the first period where all the variables are observed (first period without NaNs). % -% INPUTS +% INPUTS % - o [dseries] with N variables and T periods. % -% OUTPUTS +% OUTPUTS % - b [dates] First period where the N variables are observed (without NaNs). % Copyright (C) 2016-2017 Dynare Team diff --git a/src/@dseries/horzcat.m b/src/@dseries/horzcat.m index b6af0b02112af89a0b516fc5e41a637e830a2d38..a93d5ee76dabdc753038d30cbae57d34f7864724 100644 --- a/src/@dseries/horzcat.m +++ b/src/@dseries/horzcat.m @@ -2,24 +2,24 @@ function B = horzcat(varargin) % --*-- Unitary tests --*-- % Overloads horzcat method for dseries objects. % -% INPUTS +% INPUTS % o A1 dseries object. % o A2 dseries object. % o ... % -% OUTPUTS +% OUTPUTS % o B dseries object. % -% EXAMPLE 1 +% EXAMPLE 1 % If A, B and C are dseries objects the following syntax: -% +% % D = [A, B, C] ; % % Defines a dseries object D containing the variables appearing in A, B and C. % -% REMARKS +% REMARKS % o A1, A2, ... must not have common variables. - + % Copyright (C) 2011-2017 Dynare Team % % This file is part of Dynare. @@ -50,72 +50,72 @@ switch nargin end function a = concatenate(b,c) - [n,message] = common_strings_in_cell_arrays(b.name,c.name); - if isempty(b) - a = c; - return - end - if isempty(c) - a = b; - return - end - if n - error(['dseries::horzcat: I cannot concatenate dseries objects with common variable names (' message ')!']) - end - if ~isequal(frequency(b),frequency(c)) - error('dseries::horzcat: All time series objects must have common frequency!') +[n,message] = common_strings_in_cell_arrays(b.name,c.name); +if isempty(b) + a = c; + return +end +if isempty(c) + a = b; + return +end +if n + error(['dseries::horzcat: I cannot concatenate dseries objects with common variable names (' message ')!']) +end +if ~isequal(frequency(b),frequency(c)) + error('dseries::horzcat: All time series objects must have common frequency!') +else + a = dseries(); +end +d_nobs_flag = 0; +if ~isequal(nobs(b),nobs(c)) + d_nobs_flag = 1; +end +d_init_flag = 0; +if ~isequal(firstdate(b),firstdate(c)) + d_init_flag = 1; +end +a.name = vertcat(b.name,c.name); +a.tex = vertcat(b.tex,c.tex); +if ~( d_nobs_flag(1) || d_init_flag(1) ) + a.data = [b.data,c.data]; + a.dates = b.dates; +else + nobs_b = nobs(b); + nobs_c = nobs(c); + if firstdate(b)<=firstdate(c) + if firstdate(b)<firstdate(c) + c.data = [NaN(firstdate(c)-firstdate(b), vobs(c)); c.data]; + end else - a = dseries(); - end - d_nobs_flag = 0; - if ~isequal(nobs(b),nobs(c)) - d_nobs_flag = 1; + b.data = [NaN(firstdate(b)-firstdate(c), vobs(b)); b.data]; end - d_init_flag = 0; - if ~isequal(firstdate(b),firstdate(c)) - d_init_flag = 1; + b_last_date = firstdate(b)+nobs_b; + c_last_date = firstdate(c)+nobs_c; + if b_last_date<c_last_date + b.data = [b.data; NaN(c_last_date-b_last_date, vobs(b))]; + elseif b_last_date>c_last_date + c.data = [c.data; NaN(b_last_date-c_last_date, vobs(c))]; end - a.name = vertcat(b.name,c.name); - a.tex = vertcat(b.tex,c.tex); - if ~( d_nobs_flag(1) || d_init_flag(1) ) - a.data = [b.data,c.data]; - a.dates = b.dates; - else - nobs_b = nobs(b); - nobs_c = nobs(c); - if firstdate(b)<=firstdate(c) - if firstdate(b)<firstdate(c) - c.data = [NaN(firstdate(c)-firstdate(b), vobs(c)); c.data]; - end - else - b.data = [NaN(firstdate(b)-firstdate(c), vobs(b)); b.data]; - end - b_last_date = firstdate(b)+nobs_b; - c_last_date = firstdate(c)+nobs_c; - if b_last_date<c_last_date - b.data = [b.data; NaN(c_last_date-b_last_date, vobs(b))]; - elseif b_last_date>c_last_date - c.data = [c.data; NaN(b_last_date-c_last_date, vobs(c))]; - end - - fillerdates = dates(); - if max(c.dates) < min(b.dates) - fillerdates = max(c.dates):min(b.dates); - end - if max(b.dates) < min(c.dates) - fillerdates = max(b.dates):min(c.dates); - end - if isempty(fillerdates) - hd = [b.dates, c.dates]; - else - hd = [b.dates, fillerdates, c.dates]; - end + fillerdates = dates(); + if max(c.dates) < min(b.dates) + fillerdates = max(c.dates):min(b.dates); + end + if max(b.dates) < min(c.dates) + fillerdates = max(b.dates):min(c.dates); + end - a.data = [b.data, c.data]; - a.dates = sort(unique(hd)); + if isempty(fillerdates) + hd = [b.dates, c.dates]; + else + hd = [b.dates, fillerdates, c.dates]; end + a.data = [b.data, c.data]; + a.dates = sort(unique(hd)); +end + %@test:1 %$ % Define a data set. %$ A = [transpose(1:10),2*transpose(1:10)]; diff --git a/src/@dseries/hpcycle.m b/src/@dseries/hpcycle.m index 90dd65303f5bee08361c36fecea3c43d3f614d75..faf2e0f269c6d6437f6770baaee2d894d776676f 100644 --- a/src/@dseries/hpcycle.m +++ b/src/@dseries/hpcycle.m @@ -4,11 +4,11 @@ function ts = hpcycle(ts, lambda) % --*-- Unitary tests --*-- % % Extracts the cycle component from a dseries object using Hodrick Prescott filter. % -% INPUTS +% INPUTS % o ts dseries object. % o lambda positive scalar, trend smoothness parameter. % -% OUTPUTS +% OUTPUTS % o ts dseries object, with time series replaced by the cyclical component of the original time series. % Copyright (C) 2013 Dynare Team @@ -28,13 +28,13 @@ function ts = hpcycle(ts, lambda) % --*-- Unitary tests --*-- % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -if nargin>1 +if nargin>1 if lambda<=0 error(['dseries::hpcycle: Lambda must be a positive integer!']) end else lambda = []; -end +end for i=1:vobs(ts) ts.name(i) = {['hpcycle(' ts.name{i} ')']}; @@ -50,7 +50,7 @@ ts.data = data; %$ % Create a dataset. %$ e = .2*randn(200,1); %$ u = randn(200,1); -%$ stochastic_trend = cumsum(e); +%$ stochastic_trend = cumsum(e); %$ deterministic_trend = .1*transpose(1:200); %$ x = zeros(200,1); %$ for i=2:200 diff --git a/src/@dseries/hptrend.m b/src/@dseries/hptrend.m index 6c699f9222672c286c379e977648781f3935f181..c88561ed9a0f0348a51213a9cca4d991a464a75a 100644 --- a/src/@dseries/hptrend.m +++ b/src/@dseries/hptrend.m @@ -4,11 +4,11 @@ function ts = hptrend(ts, lambda) % --*-- Unitary tests --*-- % % Extracts the trend component from a dseries object using Hodrick Prescott filter. % -% INPUTS +% INPUTS % o ts dseries object. % o lambda positive scalar, trend smoothness parameter. % -% OUTPUTS +% OUTPUTS % o ts dseries object, with time series replaced by the trend component of the original time series. % Copyright (C) 2013 Dynare Team @@ -28,7 +28,7 @@ function ts = hptrend(ts, lambda) % --*-- Unitary tests --*-- % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -if nargin>1 +if nargin>1 if lambda<=0 error(['dseries::hptrend: Lambda must be a positive integer!']) end @@ -44,12 +44,12 @@ end ts.data = sample_hp_filter(ts.data,lambda); %@test:1 -%$ plot_flag = 0; +%$ plot_flag = 0; %$ %$ % Create a dataset. %$ e = .2*randn(200,1); %$ u = randn(200,1); -%$ stochastic_trend = cumsum(e); +%$ stochastic_trend = cumsum(e); %$ deterministic_trend = .1*transpose(1:200); %$ x = zeros(200,1); %$ for i=2:200 diff --git a/src/@dseries/insert.m b/src/@dseries/insert.m index a6f17eafdcbafab4fcdb18691f731f5dd27c602d..b27c3d9fac03b99f745e54cabd6e697582b797dc 100644 --- a/src/@dseries/insert.m +++ b/src/@dseries/insert.m @@ -61,10 +61,10 @@ end n = length(id); if n>1 - [id, jd] = sort(id); - us.data = us.data(:,jd); - us.name = us.name(jd); - us.tex = us.tex(jd); + [id, jd] = sort(id); + us.data = us.data(:,jd); + us.name = us.name(jd); + us.tex = us.tex(jd); end for i=1:n diff --git a/src/@dseries/isequal.m b/src/@dseries/isequal.m index 8a3c99a37afdae16e20d3287ab2e784f8f2d41f7..4d4afad0e3ba10d6bdaa244f28913a61b38fcf87 100644 --- a/src/@dseries/isequal.m +++ b/src/@dseries/isequal.m @@ -2,12 +2,12 @@ function C = isequal(A, B, tol) % Overloads the isequal Matlab/Octave's function. % -% INPUTS +% INPUTS % o A dseries object (T periods, N variables). % o B dseries object (T periods, N variables). % o tol tolerance parameter. % -% OUTPUTS +% OUTPUTS % o C Integer scalar equal to zero or one. % Copyright (C) 2013 Dynare Team diff --git a/src/@dseries/isnan.m b/src/@dseries/isnan.m index 4169415da2c4126dd02e6ac93d2a3970f56e5d1b..fbf9fd7ebd31d7423e6ab153ae20dba2a4c14e79 100644 --- a/src/@dseries/isnan.m +++ b/src/@dseries/isnan.m @@ -3,10 +3,10 @@ function b = isnan(o) % --*-- Unitary tests --*-- % Returns an array of logicals (true/false). Element (t,i) is true iff the i-th variable at % period number t is not a NaN. % -% INPUTS +% INPUTS % - o [dseries] with N variables and T periods. % -% OUTPUTS +% OUTPUTS % - b [logical] T*N array of logicals. diff --git a/src/@dseries/mrdivide.m b/src/@dseries/mrdivide.m index 8dfacbc5bebc0f9507c5fc5bb421a4e8714c331b..280734b54c760243e2177b4b553539d6150e94bb 100644 --- a/src/@dseries/mrdivide.m +++ b/src/@dseries/mrdivide.m @@ -39,7 +39,7 @@ function A = mrdivide(B,C) % --*-- Unitary tests --*-- % % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - + if isnumeric(B) && (isscalar(B) || isvector(B)) if ~isdseries(C) error('dseries::mrdivide: Second input argument must be a dseries object!') @@ -56,7 +56,7 @@ if isnumeric(C) && (isscalar(C) || isvector(C)) A = B; A.data = bsxfun(@rdivide,B.data,C); return -end +end if isdseries(B) && isdseries(C) % Element by element divisions of two dseries object diff --git a/src/@dseries/ne.m b/src/@dseries/ne.m index d87f15f008efbf26363b84e35f57dea3c8d36a68..d9ed6e4a05085c99af37dfe660cfeadf691d4836 100644 --- a/src/@dseries/ne.m +++ b/src/@dseries/ne.m @@ -2,15 +2,15 @@ function C = ne(A,B) % --*-- Unitary tests --*-- % Overloads ne (~=) operator. % -% INPUTS +% INPUTS % o A dseries object (T periods, N variables). % o B dseries object (T periods, N variables). % -% OUTPUTS -% o C T*N matrix of zeros and ones. Element C(t,n) is nonzero iff observation t of variable n in A and B are different. +% OUTPUTS +% o C T*N matrix of zeros and ones. Element C(t,n) is nonzero iff observation t of variable n in A and B are different. % -% REMARKS -% If the number of variables, the number of observations or the frequencies are different in A and B, the function returns one. +% REMARKS +% If the number of variables, the number of observations or the frequencies are different in A and B, the function returns one. % Copyright (C) 2013 Dynare Team % diff --git a/src/@dseries/plot.m b/src/@dseries/plot.m index 058a44dd0cf1a08af81def389fb0ac868f5dd42b..975e0098bb0f20bc1fbcebbba37ec0d4baf59a9f 100644 --- a/src/@dseries/plot.m +++ b/src/@dseries/plot.m @@ -1,6 +1,6 @@ function h = plot(ts, varargin) -% Overloads Matlab/Octave's plot function for dseries objects. +% Overloads Matlab/Octave's plot function for dseries objects. % Copyright (C) 2013 Dynare Team % @@ -70,7 +70,7 @@ switch ndseries hh = plot(ts0.data, ts1.data, varargin{2:end}); else if length(varargin)>1 - message = sprintf('dseries::plot: dseries objects %s and %s have %d>1 variables but you passed additional arguments to the plot function.\n These additional arguments won''t ne interpreted. Use the Matlab/Octave set command and the plot\n handle instead if you wish to modify the properties of the plotted time series.',inputname(1),inputname(2),nvariables); + message = sprintf('dseries::plot: dseries objects %s and %s have %d>1 variables but you passed additional arguments to the plot function.\n These additional arguments won''t ne interpreted. Use the Matlab/Octave set command and the plot\n handle instead if you wish to modify the properties of the plotted time series.',inputname(1),inputname(2),nvariables); warning(message) end hh = plot(ts0.data, ts1.data); @@ -80,5 +80,5 @@ switch ndseries end if nargout - h = hh; + h = hh; end \ No newline at end of file diff --git a/src/@dseries/plus.m b/src/@dseries/plus.m index d37b50621c7a640cfeb6e8b6739b03259ef9916b..6aa6567786d2698edf9808483192d71ccd6e8c36 100644 --- a/src/@dseries/plus.m +++ b/src/@dseries/plus.m @@ -146,7 +146,7 @@ end %$ ts1 = dseries(A,[],A_name,[]); %$ ts2 = dseries(B,[],B_name,[]); %$ ts3 = ts1+ts2; -%$ ts4 = ts3+ts1; +%$ ts4 = ts3+ts1; %$ t(1) = 1; %$ catch %$ t = 0; diff --git a/src/@dseries/private/default_name.m b/src/@dseries/private/default_name.m index 1711195c4313ddca8d499cd4d4b2f49f7cedb867..ea3f615b4f9770affd85b75e5190eaed3581fe9f 100644 --- a/src/@dseries/private/default_name.m +++ b/src/@dseries/private/default_name.m @@ -17,11 +17,8 @@ function names = default_name(dim) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - + names = {}; for i=1:dim names = vertcat(names, {['Variable_' int2str(i)]}); end - - - diff --git a/src/@dseries/set_names.m b/src/@dseries/set_names.m index d17a2e88a5d08bb113e8808260068a6c40bad315..f0afaf6f1dd60bed1b0d428fabf9ae1da06cff66 100644 --- a/src/@dseries/set_names.m +++ b/src/@dseries/set_names.m @@ -77,7 +77,7 @@ end %$ catch %$ t = 0; %$ end -%$ +%$ %$ if length(t)>1 %$ t(2) = dassert(ts2.vobs,3); %$ t(3) = dassert(ts2.nobs,10); diff --git a/src/@dseries/std.m b/src/@dseries/std.m index 7cedf390d8826e56586426cb8e488f469f42b475..845e1dd126ece3752f42e3af40fe0646669a988f 100644 --- a/src/@dseries/std.m +++ b/src/@dseries/std.m @@ -96,7 +96,7 @@ end %$ catch %$ t = 0; %$ end -%$ +%$ %$ if t(1) %$ t(2) = dassert(isequal(size(s),[1, 2]), true); %$ t(3) = dassert(max(abs(s-[.1, .1]))<.0001, true); @@ -116,7 +116,7 @@ end %$ catch %$ t = 0; %$ end -%$ +%$ %$ if t(1) %$ t(2) = dassert(isequal(size(s),[1, 2]), true); %$ t(3) = dassert(max(abs(s-[.1, .1]))<.0001, true); diff --git a/src/@dseries/subsasgn.m b/src/@dseries/subsasgn.m index f34436ff5db3cbe441b4707dd2d57fdc1a824083..2c3ca51d96296f88e39a4407e6edc90b87d5896a 100644 --- a/src/@dseries/subsasgn.m +++ b/src/@dseries/subsasgn.m @@ -28,156 +28,156 @@ function A = subsasgn(A,S,B) % --*-- Unitary tests --*-- merge_dseries_objects = 1; switch length(S) - case 1 - switch S(1).type - case '{}' % Multiple variable selection. - if ~isequal(numel(S(1).subs),numel(unique(S(1).subs))) - error('dseries::subsasgn: Wrong syntax!') - end - for i=1:numel(S(1).subs) - element = S(1).subs{i}; - % Implicit loop. - idArobase = strfind(element,'@'); - if mod(length(idArobase),2) - error('dseries::subsasgn: (Implicit loops) The number of @ symbols must be even!') - end - % regular expression. - idBracket.open = strfind(element, '['); - idBracket.close = strfind(element, ']'); - if ~isequal(length(idBracket.open),length(idBracket.open)) - error('dseries::subsasgn: (Matlab/Octave''s regular expressions) Check opening and closing square brackets!') - end - % Loops and regular expressions are not compatible - if length(idArobase) && length(idBracket.open) - error(['dseries::subsasgn: You cannot use implicit loops and regular expressions in the same rule!']) - end - if ~isempty(idArobase) - elements = build_list_of_variables_with_loops({}, idArobase, element, {}); - S(1).subs = replace_object_in_a_one_dimensional_cell_array(S(1).subs, elements(:), i); - end - if ~isempty(idBracket.open) - elements = build_list_of_variables_with_regexp(A.name, idBracket, element, {}); - S(1).subs = replace_object_in_a_one_dimensional_cell_array(S(1).subs, elements(:), i); - end - end - if isempty(B) - for i=1:length(S(1).subs) - A = remove(A,S(1).subs{i}); - end - return - end - if ~isequal(length(S(1).subs),vobs(B)) - error('dseries::subsasgn: Wrong syntax!') - end - if ~isequal(S(1).subs(:),B.name) - for i = 1:vobs(B) - if ~isequal(S(1).subs{i},B.name{i}) - % Rename a variable. - id = find(strcmp(S(1).subs{i},A.name)); - if isempty(id) - % Add a new variable a change its name. - B.name(i) = {S(1).subs{i}}; - B.tex(i) = {name2tex(S(1).subs{i})}; - else - % Rename variable and change its content. - B.name(i) = A.name(id); - B.tex(i) = A.tex(id); - end - end - end - end - case '.' - if isequal(S(1).subs,'init') && isdates(B) && isequal(length(B),1) - % Change the initial date (update dates member) - A.dates = B:B+(nobs(A)-1); - return - elseif isequal(S(1).subs,'dates') && isdates(B) - % Overwrite the dates member - A.dates = B; - return - elseif ismember(S(1).subs,{'data','name','tex'}) - error(['dseries::subsasgn: You cannot overwrite ' S(1).subs ' member!']) - elseif ~isequal(S(1).subs,B.name) - % Single variable selection. - if ~isequal(S(1).subs,B.name{1}) - % Rename a variable. - id = find(strcmp(S(1).subs,A.name)); - if isempty(id) - % Add a new variable a change its name. - B.name(1) = {S(1).subs}; - B.tex(1) = {name2tex(S(1).subs)}; - else - % Rename variable and change its content. - B.name(1) = A.name(id); - B.tex(1) = A.tex(id); - end - end - end - case '()' % Date(s) selection - if isdates(S(1).subs{1}) || isdate(S(1).subs{1}) - if isdate(S(1).subs{1}) - Dates = dates(S(1).subs{1}); + case 1 + switch S(1).type + case '{}' % Multiple variable selection. + if ~isequal(numel(S(1).subs),numel(unique(S(1).subs))) + error('dseries::subsasgn: Wrong syntax!') + end + for i=1:numel(S(1).subs) + element = S(1).subs{i}; + % Implicit loop. + idArobase = strfind(element,'@'); + if mod(length(idArobase),2) + error('dseries::subsasgn: (Implicit loops) The number of @ symbols must be even!') + end + % regular expression. + idBracket.open = strfind(element, '['); + idBracket.close = strfind(element, ']'); + if ~isequal(length(idBracket.open),length(idBracket.open)) + error('dseries::subsasgn: (Matlab/Octave''s regular expressions) Check opening and closing square brackets!') + end + % Loops and regular expressions are not compatible + if length(idArobase) && length(idBracket.open) + error(['dseries::subsasgn: You cannot use implicit loops and regular expressions in the same rule!']) + end + if ~isempty(idArobase) + elements = build_list_of_variables_with_loops({}, idArobase, element, {}); + S(1).subs = replace_object_in_a_one_dimensional_cell_array(S(1).subs, elements(:), i); + end + if ~isempty(idBracket.open) + elements = build_list_of_variables_with_regexp(A.name, idBracket, element, {}); + S(1).subs = replace_object_in_a_one_dimensional_cell_array(S(1).subs, elements(:), i); + end + end + if isempty(B) + for i=1:length(S(1).subs) + A = remove(A,S(1).subs{i}); + end + return + end + if ~isequal(length(S(1).subs),vobs(B)) + error('dseries::subsasgn: Wrong syntax!') + end + if ~isequal(S(1).subs(:),B.name) + for i = 1:vobs(B) + if ~isequal(S(1).subs{i},B.name{i}) + % Rename a variable. + id = find(strcmp(S(1).subs{i},A.name)); + if isempty(id) + % Add a new variable a change its name. + B.name(i) = {S(1).subs{i}}; + B.tex(i) = {name2tex(S(1).subs{i})}; + else + % Rename variable and change its content. + B.name(i) = A.name(id); + B.tex(i) = A.tex(id); + end + end + end + end + case '.' + if isequal(S(1).subs,'init') && isdates(B) && isequal(length(B),1) + % Change the initial date (update dates member) + A.dates = B:B+(nobs(A)-1); + return + elseif isequal(S(1).subs,'dates') && isdates(B) + % Overwrite the dates member + A.dates = B; + return + elseif ismember(S(1).subs,{'data','name','tex'}) + error(['dseries::subsasgn: You cannot overwrite ' S(1).subs ' member!']) + elseif ~isequal(S(1).subs,B.name) + % Single variable selection. + if ~isequal(S(1).subs,B.name{1}) + % Rename a variable. + id = find(strcmp(S(1).subs,A.name)); + if isempty(id) + % Add a new variable a change its name. + B.name(1) = {S(1).subs}; + B.tex(1) = {name2tex(S(1).subs)}; else - Dates = S(1).subs{1}; + % Rename variable and change its content. + B.name(1) = A.name(id); + B.tex(1) = A.tex(id); end - [junk, tdx] = intersect(A.dates.time,Dates.time,'rows'); - if isdseries(B) - [junk, tdy] = intersect(B.dates.time,Dates.time,'rows'); - if isempty(tdy) - error('dseries::subsasgn: Periods of the dseries objects on the left and right hand sides must intersect!') - end - if ~isequal(vobs(A), vobs(B)) - error('dseries::subsasgn: Dimension error! The number of variables on the left and right hand side must match.') - end - A.data(tdx,:) = B.data(tdy,:); - merge_dseries_objects = 0; - elseif isnumeric(B) - merge_dseries_objects = 0; - if isequal(length(tdx),rows(B)) - if isequal(columns(A.data),columns(B)) - A.data(tdx,:) = B; - else - error('dseries::subsasgn: Dimension error! The number of variables on the left and right hand side must match.') - end - else - error('dseries::subsassgn: Dimension error! The number of periods on the left and right hand side must match.') - end - else - error('dseries::subsasgn: The object on the right hand side must be a dseries object or a numeric array!') - end - elseif ischar(S(1).subs{1}) && isequal(S(1).subs{1},':') && isempty(A) - if isnumeric(B) - if isequal(rows(B),1) - A.data = repmat(B,A.dates.ndat,1); - elseif isequal(rows(B),A.dates.ndat) - A.data = B; - else - error('dseries::subsasgn: Wrong syntax!') - end - if isempty(A.name) - A.name = default_name(vobs(A)); - A.tex = name2tex(A.name); - end - elseif isdseries(B) - if isequal(nobs(B), 1) - A.data = repmat(B.data,A.dates.ndat,1); - elseif isequal(nobs(B), A.dates.ndat) - A.data = B; - else - error('dseries::subsasgn: Wrong syntax!') - end - if isempty(A.name) - A.name = B.name; - A.tex = B.tex; - end - end - return - else - error('dseries::subsasgn: Wrong syntax!') - end - otherwise - error('dseries::subsasgn: Wrong syntax!') - end + end + end + case '()' % Date(s) selection + if isdates(S(1).subs{1}) || isdate(S(1).subs{1}) + if isdate(S(1).subs{1}) + Dates = dates(S(1).subs{1}); + else + Dates = S(1).subs{1}; + end + [junk, tdx] = intersect(A.dates.time,Dates.time,'rows'); + if isdseries(B) + [junk, tdy] = intersect(B.dates.time,Dates.time,'rows'); + if isempty(tdy) + error('dseries::subsasgn: Periods of the dseries objects on the left and right hand sides must intersect!') + end + if ~isequal(vobs(A), vobs(B)) + error('dseries::subsasgn: Dimension error! The number of variables on the left and right hand side must match.') + end + A.data(tdx,:) = B.data(tdy,:); + merge_dseries_objects = 0; + elseif isnumeric(B) + merge_dseries_objects = 0; + if isequal(length(tdx),rows(B)) + if isequal(columns(A.data),columns(B)) + A.data(tdx,:) = B; + else + error('dseries::subsasgn: Dimension error! The number of variables on the left and right hand side must match.') + end + else + error('dseries::subsassgn: Dimension error! The number of periods on the left and right hand side must match.') + end + else + error('dseries::subsasgn: The object on the right hand side must be a dseries object or a numeric array!') + end + elseif ischar(S(1).subs{1}) && isequal(S(1).subs{1},':') && isempty(A) + if isnumeric(B) + if isequal(rows(B),1) + A.data = repmat(B,A.dates.ndat,1); + elseif isequal(rows(B),A.dates.ndat) + A.data = B; + else + error('dseries::subsasgn: Wrong syntax!') + end + if isempty(A.name) + A.name = default_name(vobs(A)); + A.tex = name2tex(A.name); + end + elseif isdseries(B) + if isequal(nobs(B), 1) + A.data = repmat(B.data,A.dates.ndat,1); + elseif isequal(nobs(B), A.dates.ndat) + A.data = B; + else + error('dseries::subsasgn: Wrong syntax!') + end + if isempty(A.name) + A.name = B.name; + A.tex = B.tex; + end + end + return + else + error('dseries::subsasgn: Wrong syntax!') + end + otherwise + error('dseries::subsasgn: Wrong syntax!') + end case 2 merge_dseries_objects = 0; if ((isequal(S(1).type,'{}') || isequal(S(1).type,'.')) && isequal(S(2).type,'()')) diff --git a/src/@dseries/tex_rename.m b/src/@dseries/tex_rename.m index 801b8df789187607821cd09a19b4e505258e5af3..1414cd41708d4cc40de94ab7464eb1bf54f7a67d 100644 --- a/src/@dseries/tex_rename.m +++ b/src/@dseries/tex_rename.m @@ -31,7 +31,7 @@ end assert(ischar(newtexname) || (iscellstr(newtexname) && length(newtexname) == vobs(ts)), ... ['dseries::tex_rename: third input argument (newtexname) name must either be a string' ... - ' or a cell array of strings with the same number of entries as varibles in the dseries']); + ' or a cell array of strings with the same number of entries as varibles in the dseries']); if nargin == 2 idname = 1; diff --git a/src/@dseries/vertcat.m b/src/@dseries/vertcat.m index 387885ac9e1c6ec6d850bda8844e2a6debd1ad6e..d77e89e7d75cb5e2d3e0231ea4a5abb983dbcaab 100644 --- a/src/@dseries/vertcat.m +++ b/src/@dseries/vertcat.m @@ -7,7 +7,7 @@ function a = vertcat(varargin) % --*-- Unitary tests --*-- %! Method of the dseries class. %! @sp 1 %! This method overloads the vertical concatenation operator, so that -%! two (or more) time series objects containing the same variables +%! two (or more) time series objects containing the same variables %! can be merged using the following syntax: %! %! a = [b; c; d]; @@ -59,29 +59,29 @@ elseif nargin>1 end function d = vertcat_(b, c) - d = NaN; - if ~isequal(frequency(b), frequency(c)) - error('dseries::vertcat: Frequencies must be common!') - end - if ~isequal(vobs(b), vobs(c)) - error('dseries::vertcat: Number of variables must be common!') - end - reorder_variables_in_c = false; - if ~isequal(b.name, c.name) - [t, idx] = ismember(b.name, c.name); - if all(t) - reorder_variables_in_c = true; - else - error('dseries::vertcat: Variables must be common!') - end - end - d = b; - if reorder_variables_in_c - d.data = [b.data; c.data(:,idx)]; +d = NaN; +if ~isequal(frequency(b), frequency(c)) + error('dseries::vertcat: Frequencies must be common!') +end +if ~isequal(vobs(b), vobs(c)) + error('dseries::vertcat: Number of variables must be common!') +end +reorder_variables_in_c = false; +if ~isequal(b.name, c.name) + [t, idx] = ismember(b.name, c.name); + if all(t) + reorder_variables_in_c = true; else - d.data = [b.data; c.data]; + error('dseries::vertcat: Variables must be common!') end - d.dates = [b.dates; c.dates]; +end +d = b; +if reorder_variables_in_c + d.data = [b.data; c.data(:,idx)]; +else + d.data = [b.data; c.data]; +end +d.dates = [b.dates; c.dates]; %@test:1 %$ % Define a data set. diff --git a/src/read/load_csv_file_data.m b/src/read/load_csv_file_data.m index 3a65360cafbb4eb70f61c2892a50067f7bdd0876..32b6b52848e5b108b170d807d098cd6e10fe7415 100644 --- a/src/read/load_csv_file_data.m +++ b/src/read/load_csv_file_data.m @@ -2,16 +2,16 @@ function [freq, init, data, varlist] = load_csv_file_data(file) % --*-- Unitary %function [freq, init, data, varlist] = load_csv_file_data(file) % Loads data in a csv file. % -% INPUTS +% INPUTS % o file string, name of the csv file (with path). % -% OUTPUTS +% OUTPUTS % o freq integer scalar equal to 1, 4, 12 or 52 (for annual, quaterly, monthly or weekly frequencies). % o init dates object, initial date in the dataset. % o data matrix of doubles, the data. % o varlist cell of strings, names of the variables. % -% REMARKS +% REMARKS % The varlist output will be set only if the first line contains variable % names. Similarly, if the first column does not contain dates, then % freq will be 1 and init will be year 1. diff --git a/src/read/load_m_file_data.m b/src/read/load_m_file_data.m index cc724714112dc140558ff31b87bac60ce54b81d9..1be2c2622f3179c29c1baf1322a17549aa45fca3 100644 --- a/src/read/load_m_file_data.m +++ b/src/read/load_m_file_data.m @@ -2,18 +2,18 @@ function [freq,init,data,varlist,tex] = load_m_file_data(file) % Loads data in a matlab/octave script. % -% INPUTS +% INPUTS % o file string, name of the matlab/octave script (with path) % -% OUTPUTS +% OUTPUTS % o freq integer scalar equal to 1, 4, 12 or 52 (for annual, quaterly, monthly or weekly frequencies). % o init dates object, initial date in the dataset. % o data matrix of doubles, the data. % o varlist cell of strings, names of the variables. % -% REMARKS -% The frequency and initial date can be specified with variables FREQ__ and INIT__ in the matlab/octave script. FREQ__ must -% be a scalar integer and INIT__ a string like '1938M11', '1945Q3', '1973W3' or '2009A'. If these variables are not specified +% REMARKS +% The frequency and initial date can be specified with variables FREQ__ and INIT__ in the matlab/octave script. FREQ__ must +% be a scalar integer and INIT__ a string like '1938M11', '1945Q3', '1973W3' or '2009A'. If these variables are not specified % default values for freq and init are 1 and dates(1,1). % Copyright (C) 2012-2015 Dynare Team @@ -94,7 +94,7 @@ if isempty(varlist0) || isequal(list_of_variables(current_variable_index).name,'varlist0') ... || isequal(list_of_variables(current_variable_index).name,'list_of_variables') ... || isequal(list_of_variables(current_variable_index).name,'tex') ... - continue + continue end if list_of_variables(current_variable_index).global || list_of_variables(current_variable_index).persistent % A variable cannot be a global or persistent variable. @@ -117,7 +117,7 @@ if isempty(varlist0) end else for current_variable_index=1:length(varlist0) - eval(['data = [data, ' varlist0{current_variable_index} '];']) + eval(['data = [data, ' varlist0{current_variable_index} '];']) end varlist = varlist0; end diff --git a/src/read/load_mat_file_data.m b/src/read/load_mat_file_data.m index d83995674f5d479b7885ca5d1f7df78d79c22740..8f12c7ad4ef227314b5ba055f55e023238c36876 100644 --- a/src/read/load_mat_file_data.m +++ b/src/read/load_mat_file_data.m @@ -2,18 +2,18 @@ function [freq,init,data,varlist,tex] = load_mat_file_data(file) % --*-- Unitar % Loads data in a matlab/octave mat-file. % -% INPUTS +% INPUTS % o file string, name of the matlab/octave mat file (with path) % -% OUTPUTS +% OUTPUTS % o freq integer scalar equal to 1, 4, 12 or 52 (for annual, quaterly, monthly or weekly frequencies). % o init dates object, initial date in the dataset. % o data matrix of doubles, the data. % o varlist cell of strings, names of the variables. % -% REMARKS -% The frequency and initial date can be specified with variables FREQ__ and INIT__ in the matlab/octave binary file. FREQ__ must -% be a scalar integer and INIT__ a string like '1938M11', '1945Q3', '1973W3' or '2009A'. If these variables are not specified +% REMARKS +% The frequency and initial date can be specified with variables FREQ__ and INIT__ in the matlab/octave binary file. FREQ__ must +% be a scalar integer and INIT__ a string like '1938M11', '1945Q3', '1973W3' or '2009A'. If these variables are not specified % default values for freq and init are 1 and dates(1,1). % Copyright (C) 2012-2017 Dynare Team diff --git a/src/read/load_xls_file_data.m b/src/read/load_xls_file_data.m index 143e58ab44b030adf06e7492cbce509a23a71ded..439056de64d680a260cc82bbe38b546e0a4b9cbe 100644 --- a/src/read/load_xls_file_data.m +++ b/src/read/load_xls_file_data.m @@ -2,18 +2,18 @@ function [freq, init, data, varlist] = load_xls_file_data(file, sheet, range) % Loads data in a xls file. % -% INPUTS +% INPUTS % o file string, name of the file (with extension). % o sheet string, name of the sheet to be read. % o range string of the form 'B2:D6' % -% OUTPUTS +% OUTPUTS % o freq integer scalar (1, 4, 12 or 52), code for frequency. % o init dates object, initial date of the sample. % o data matrix of doubles, the raw data. % o varlist cell of strings (column), names of the variables in the database. % -% REMARKS +% REMARKS % The range argument is only available on windows platform (with Excel installed). % Copyright (C) 2013-2015 Dynare Team @@ -45,13 +45,13 @@ if nargin<3 || isempty(range) end if isoctave && ~user_has_octave_forge_package('io') - try - pkg load io - catch - error(['The io package is required to read CSV files from Octave. ' ... - 'It can be installed by running the following from the Octave ' ... - ' command line: pkg install -forge io']); - end + try + pkg load io + catch + error(['The io package is required to read CSV files from Octave. ' ... + 'It can be installed by running the following from the Octave ' ... + ' command line: pkg install -forge io']); + end end % Check file extension. @@ -87,18 +87,18 @@ if isequal(t1,0) && isequal(t2,0) notime = 1; noname = 1; elseif isequal(t2,1) && t1>=t2 && n2~=t2 %only one column present, but no var name in header text - % The file contains no informations about the dates. + % The file contains no informations about the dates. notime = 0; noname = 1; elseif isequal(t2,1) && t1>=t2 && n2==t2 %only one column present with var name in header text - % The file contains no informations about the variables. + % The file contains no informations about the variables. notime = 1; noname = 0; elseif isequal(t1,1) && t2>=t1 % The file contains no informations about the dates. notime = 1; noname = 0; -else +else % The file contains informations about the variables and dates. notime = 0; noname = 0; @@ -135,7 +135,7 @@ if ~noname else varlist = transpose(txt(1,2:end)); end - % Remove leading and trailing white spaces + % Remove leading and trailing white spaces for i=1:length(varlist) varlist(i) = {strtrim(varlist{i})}; end diff --git a/src/utilities/file/check_file_extension.m b/src/utilities/file/check_file_extension.m index 70107015e0e3c38bd24fbe2dc2358b10e0beeb30..472b0aed1bc7f8e6ccc6301897a7590a8d22e4d0 100644 --- a/src/utilities/file/check_file_extension.m +++ b/src/utilities/file/check_file_extension.m @@ -3,11 +3,11 @@ function b = check_file_extension(file,type) % Check file extension of a file. Returns 1 (true) if the extension of ```file``` is equal to % ```type```, 0 (false) otherwise. % -% INPUTS +% INPUTS % - file [str] file name. % - type [str] file extension. % -% OUTPUTS +% OUTPUTS % - b [bool] diff --git a/src/utilities/from/from.m b/src/utilities/from/from.m index feb2a80c313727d81ccfadcbe21980a01af26a96..0b8a0c7f3d0038418b7d8176c9872c917c2772c9 100644 --- a/src/utilities/from/from.m +++ b/src/utilities/from/from.m @@ -281,7 +281,7 @@ end % Put all the variables in a unique dseries object. list_of_variables = leadlagtable{1,1}; for i=2:number_of_variables - list_of_variables = [list_of_variables, ',' leadlagtable{i,1}]; + list_of_variables = [list_of_variables, ',' leadlagtable{i,1}]; end eval(sprintf('tmp = [%s];', list_of_variables)); @@ -376,52 +376,52 @@ else end function msg = get_error_message_0(msg) - if ~nargin - msg = sprintf('Wrong syntax! The correct syntax is:\n\n'); - else - msg = [msg, sprintf('The correct syntax is:\n\n')]; - end - msg = [msg, sprintf(' from d1 to d2 do SOMETHING\n\n')]; - msg = [msg, sprintf('where d1<d2 are dates objects, and SOMETHING is a recursive expression involving dseries objects.')]; +if ~nargin + msg = sprintf('Wrong syntax! The correct syntax is:\n\n'); +else + msg = [msg, sprintf('The correct syntax is:\n\n')]; +end +msg = [msg, sprintf(' from d1 to d2 do SOMETHING\n\n')]; +msg = [msg, sprintf('where d1<d2 are dates objects, and SOMETHING is a recursive expression involving dseries objects.')]; function index = extractindex(str) - index = regexpi(str,'\(t\)|\(t\-\d\)|\(t\+\d\)','match'); +index = regexpi(str,'\(t\)|\(t\-\d\)|\(t\+\d\)','match'); function i = index2num(id) - if isequal('(t)',id) - i = 0; - return - end - if isequal('-',id(3)) - i = - str2num(id(4:end-1)); - else - i = str2num(id(4:end-1)); - end +if isequal('(t)',id) + i = 0; + return +end +if isequal('-',id(3)) + i = - str2num(id(4:end-1)); +else + i = str2num(id(4:end-1)); +end function id = num2index(i) - if isequal(i,0) - id = '(t)'; - return - end - if i<0 - id = ['(t-' int2str(abs(i)) ')']; - else - id = ['(t+' int2str(i) ')']; - end +if isequal(i,0) + id = '(t)'; + return +end +if i<0 + id = ['(t-' int2str(abs(i)) ')']; +else + id = ['(t+' int2str(i) ')']; +end function i = isassignedvariable(var,expr) - idv = strfind(expr,var); - idq = strfind(expr,'='); - if ~isempty(idv) - if idv(1)<idq - i = 1; - return - end +idv = strfind(expr,var); +idq = strfind(expr,'='); +if ~isempty(idv) + if idv(1)<idq + i = 1; + return end - i = 0; +end +i = 0; %@test:1 %$ try diff --git a/src/utilities/insert/insert_column_vector_in_a_matrix.m b/src/utilities/insert/insert_column_vector_in_a_matrix.m index 11884240161c4f9473bdacc0303774e3b2e1b9f0..c9736ce0ece18f18f2030f05077936db9cb6b3b6 100644 --- a/src/utilities/insert/insert_column_vector_in_a_matrix.m +++ b/src/utilities/insert/insert_column_vector_in_a_matrix.m @@ -2,12 +2,12 @@ function matrix = insert_column_vector_in_a_matrix(matrix, vector, i) % --*-- U % Inserts a vector in a matrix in a column specified by i. % -% INPUTS +% INPUTS % - matrix [float] n*m matrix. % - vector [float] n*1 vector. % - i [integer] scalar between 1 and m+1. Default value is m+1. % -% OUTPUTS +% OUTPUTS % - matrix [float] n*(m+1) matrix. % Copyright (C) 2013-2015 Dynare Team diff --git a/src/utilities/insert/insert_object_in_a_one_dimensional_cell_array.m b/src/utilities/insert/insert_object_in_a_one_dimensional_cell_array.m index c8ce6632fd6e6d5a82c3a13a7a04bdebf5284b24..43c466ef00e92e179a547ce3f1f93decd2eb2b2f 100644 --- a/src/utilities/insert/insert_object_in_a_one_dimensional_cell_array.m +++ b/src/utilities/insert/insert_object_in_a_one_dimensional_cell_array.m @@ -2,12 +2,12 @@ function one_dimensional_cell_array = insert_object_in_a_one_dimensional_cell_ar % Inserts an object in a one dimensional cell array in a position specified by i. % -% INPUTS +% INPUTS % - one_dimensional_cell_array [any] cell array with n objects. % - object [any] scalar object. % - i [integer] scalar between 1 and n+1. Default value is m+1. % -% OUTPUTS +% OUTPUTS % - one_dimensional_cell_array [any] cell array with n+1 elements. % Copyright (C) 2013-2015 Dynare Team diff --git a/src/utilities/insert/replace_object_in_a_one_dimensional_cell_array.m b/src/utilities/insert/replace_object_in_a_one_dimensional_cell_array.m index b5fcfff553733a3d996ddca09c9bc831df5223f8..5e545c2d77ff550ed554bce7a58b990fefe0aec2 100644 --- a/src/utilities/insert/replace_object_in_a_one_dimensional_cell_array.m +++ b/src/utilities/insert/replace_object_in_a_one_dimensional_cell_array.m @@ -2,12 +2,12 @@ function one_dimensional_cell_array = replace_object_in_a_one_dimensional_cell_a % Replaces an object in a one dimensional cell array in a position specified by i. % -% INPUTS +% INPUTS % - one_dimensional_cell_array [any] cell array with n objects. % - object [any] scalar object. % - i [integer] scalar between 1 and n. % -% OUTPUTS +% OUTPUTS % - one_dimensional_cell_array [any] cell array with n+1 elements. % Copyright (C) 2013-2015 Dynare Team diff --git a/src/utilities/is/iscellofchar.m b/src/utilities/is/iscellofchar.m index a9100f61ca57a94d1a32642753a3d4d57ad1cfdb..c6185af7d53dc17e693cf213053a55ed66f33116 100644 --- a/src/utilities/is/iscellofchar.m +++ b/src/utilities/is/iscellofchar.m @@ -2,10 +2,10 @@ function a = iscellofchar(b) % Returns true iff ```b``` is a cell of char. % -% INPUTS +% INPUTS % - b [any] % -% OUTPUTS +% OUTPUTS % - a [bool] % Copyright (C) 2012-2015 Dynare Team diff --git a/src/utilities/is/isglobalinbase.m b/src/utilities/is/isglobalinbase.m index 8280ac610a04155d96fd4b0cec013697c6708431..6466d8682d4469a24245ed8ca307643804b6b632 100644 --- a/src/utilities/is/isglobalinbase.m +++ b/src/utilities/is/isglobalinbase.m @@ -2,10 +2,10 @@ function a = isglobalinbase(var) % Returns true iff ```var``` is a global variable in the main workspace. % -% INPUTS +% INPUTS % - var [any] % -% OUTPUTS +% OUTPUTS % - a [bool] % Copyright (C) 2013-2015 Dynare Team diff --git a/src/utilities/missing/demean/demean.m b/src/utilities/missing/demean/demean.m index bcfa3b5dbfad4934c9561e00de77a09771f52186..8e77f55f438d298acc60f5792430b7760dd548c8 100644 --- a/src/utilities/missing/demean/demean.m +++ b/src/utilities/missing/demean/demean.m @@ -2,10 +2,10 @@ function c = demean(x) % Removes the mean of each column of a matrix. % -% INPUTS +% INPUTS % - x [float] T*n matrix. % -% OUTPUTS +% OUTPUTS % - c [float] T*n matrix, the demeaned matrix x. % Copyright (C) 2011-2015 Dynare Team diff --git a/src/utilities/missing/ndim/ndim.m b/src/utilities/missing/ndim/ndim.m index dc62e80d231b86bdef33ce6866ccea676b9561ec..601d66c1d71d8d569b1dc1e46caa74afbcd7e343 100644 --- a/src/utilities/missing/ndim/ndim.m +++ b/src/utilities/missing/ndim/ndim.m @@ -2,10 +2,10 @@ function n = ndim(x) % Returns the number of non singleton dimensions of a matlab array. % -% INPUTS +% INPUTS % - x [array] % -% OUTPUTS +% OUTPUTS % - n [integer] number of non singleton dimensions. % Copyright (C) 2012-2015 Dynare Team diff --git a/src/utilities/missing/sample_hp_filter/sample_hp_filter.m b/src/utilities/missing/sample_hp_filter/sample_hp_filter.m index 77dddb82ad59ca4b048ca13f0f16992cd7a2cbd1..c08f5f9bbcf54573f3da14c08e634780400b5c1f 100644 --- a/src/utilities/missing/sample_hp_filter/sample_hp_filter.m +++ b/src/utilities/missing/sample_hp_filter/sample_hp_filter.m @@ -2,11 +2,11 @@ function [hptrend,hpcycle] = sample_hp_filter(y,s) % HP filters a collection of time series. % -% INPUTS +% INPUTS % y [double] T*n matrix of data (n is the number of variables) % s [double] scalar, smoothing parameter. % -% OUTPUTS +% OUTPUTS % hptrend [double] T*n matrix, trend component of y. % hpcycle [double] T*n matrix, cycle component of y. diff --git a/src/utilities/str/common_strings_in_cell_arrays.m b/src/utilities/str/common_strings_in_cell_arrays.m index 724183fb37fafb52b689a21869cf637c807143b8..f182656ce95b9d423144fd5795b6fc4446ed0762 100644 --- a/src/utilities/str/common_strings_in_cell_arrays.m +++ b/src/utilities/str/common_strings_in_cell_arrays.m @@ -2,11 +2,11 @@ function [n,message] = common_strings_in_cell_arrays(a,b) % Counts the number of common strings in two cell arrays of strings ```a``` and ```b```. % -% INPUTS +% INPUTS % - a [cell] One dimensional cell array of strings. % - b [cell] One dimensional cell array of strings. % -% OUTPUTS +% OUTPUTS % - n [integer] scalar, the number of common strings. % - message [string] formatted list of common strings. @@ -107,4 +107,3 @@ end %$ end %$ T = all(t); %@eof:3 - diff --git a/src/utilities/str/get_random_string.m b/src/utilities/str/get_random_string.m index 44a45f4aabaadbe56d3ed0ca49036c0cce248b12..cac13f347b8666495b5ddc37c9e9972936217c5f 100644 --- a/src/utilities/str/get_random_string.m +++ b/src/utilities/str/get_random_string.m @@ -2,10 +2,10 @@ function s = get_random_string(n); % Builds a random string (starting with a letter). % -% INPUTS +% INPUTS % - n [integer] scalar, length of the generated string. % -% OUTPUTS +% OUTPUTS % - s [string] random string of length n. % Copyright (C) 2012-2015 Dynare Team diff --git a/src/utilities/str/name2tex.m b/src/utilities/str/name2tex.m index 3ce3575d97aa99ca7527fca635732a40ba6dcecb..d9e7946b20a432561947a62c230bb569c3da1f15 100644 --- a/src/utilities/str/name2tex.m +++ b/src/utilities/str/name2tex.m @@ -4,11 +4,11 @@ function tex = name2tex(name, info) % --*-- Unitary tests --*-- % % Builds a random string (starting with a letter). % -% INPUTS +% INPUTS % - name [string or cell of strings] name(s) to be converted. % - info [integer] scalar equal to 0 or 1 (adds curly braces for indices). % -% OUTPUTS +% OUTPUTS % - tex [string or cell of strings] % Copyright (C) 2012-2016 Dynare Team diff --git a/src/utilities/variables/build_list_of_variables_with_loops.m b/src/utilities/variables/build_list_of_variables_with_loops.m index 47562091a92a070fe2f82e4e3dd7fb2784ae4858..5439f276a83ed3f3a4bb2c938fe6ff2a70562832 100644 --- a/src/utilities/variables/build_list_of_variables_with_loops.m +++ b/src/utilities/variables/build_list_of_variables_with_loops.m @@ -18,7 +18,7 @@ function list_of_variables = build_list_of_variables_with_loops(o_list_of_variab % along with Dynare. If not, see <http://www.gnu.org/licenses/>. checknames = ~isempty(o_list_of_variables); - + NumberOfImplicitLoops = .5*length(idArobase); idComma = cell(NumberOfImplicitLoops,1); @@ -39,7 +39,7 @@ switch NumberOfImplicitLoops expression = expressions{1}; idVariables_ = []; while ~isempty(expression) - [token, expression] = strtok(expression,','); + [token, expression] = strtok(expression,','); candidate = [VariableName(1:idArobase(1)-1), token, VariableName(idArobase(2)+1:end)]; if checknames id = find(strcmp(candidate,o_list_of_variables)); diff --git a/src/utilities/variables/build_list_of_variables_with_regexp.m b/src/utilities/variables/build_list_of_variables_with_regexp.m index 90d76c93debbbd4481d1d96089f4f3f1ac843162..d1c184cdc02671e01cf2884a522ff05c7da9fb29 100644 --- a/src/utilities/variables/build_list_of_variables_with_regexp.m +++ b/src/utilities/variables/build_list_of_variables_with_regexp.m @@ -47,10 +47,10 @@ list_of_variables = vertcat(list_of_variables, VariableName); function b = isnotempty_cell(CellArray) - CellArrayDimension = size(CellArray); - b = NaN(CellArrayDimension); - for i=1:CellArrayDimension(1) - for j = 1:CellArrayDimension(2) - b(i,j) = ~isempty(CellArray{i,j}); - end +CellArrayDimension = size(CellArray); +b = NaN(CellArrayDimension); +for i=1:CellArrayDimension(1) + for j = 1:CellArrayDimension(2) + b(i,j) = ~isempty(CellArray{i,j}); end +end