From c5af1d43ed425e31ac8beacddbbabacd34ee5031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Mon, 28 Jul 2014 17:48:49 +0200 Subject: [PATCH] Removed nobs and vobs members in @dseries class. The syntax to get the number of observations and the number of variables remains unaffected by this commit. If ts a @dseries object, ts.nobs and ts.vobs are respectively the number of observations and the number of variables. --- matlab/@dseries/abs.m | 11 ++++---- matlab/@dseries/align.m | 16 +++++------ matlab/@dseries/baxter_king_filter.m | 5 ++-- matlab/@dseries/chain.m | 5 ++-- matlab/@dseries/check.m | 6 ++--- matlab/@dseries/cumprod.m | 12 ++++----- matlab/@dseries/cumsum.m | 12 ++++----- matlab/@dseries/detrend.m | 6 ++--- matlab/@dseries/disp.m | 8 +++--- matlab/@dseries/display.m | 40 ++++++++++++++-------------- matlab/@dseries/dseries.m | 40 +++++++++++----------------- matlab/@dseries/end.m | 2 +- matlab/@dseries/eq.m | 4 +-- matlab/@dseries/exp.m | 2 +- matlab/@dseries/extract.m | 2 -- matlab/@dseries/horzcat.m | 21 +++++++-------- matlab/@dseries/hpcycle.m | 2 +- matlab/@dseries/hptrend.m | 2 +- matlab/@dseries/insert.m | 5 ---- matlab/@dseries/isempty.m | 4 +-- matlab/@dseries/isequal.m | 4 +-- matlab/@dseries/lag.m | 4 +-- matlab/@dseries/lead.m | 4 +-- matlab/@dseries/log.m | 2 +- matlab/@dseries/merge.m | 39 +++++++++++++-------------- matlab/@dseries/minus.m | 29 ++++++++++---------- matlab/@dseries/mpower.m | 22 +++++++-------- matlab/@dseries/mrdivide.m | 29 ++++++++++---------- matlab/@dseries/mtimes.m | 29 ++++++++++---------- matlab/@dseries/ne.m | 4 +-- matlab/@dseries/nobs.m | 22 +++++++++++++++ matlab/@dseries/plot.m | 16 +++++------ matlab/@dseries/plus.m | 35 +++++++++++------------- matlab/@dseries/pop.m | 3 +-- matlab/@dseries/qdiff.m | 4 +-- matlab/@dseries/qgrowth.m | 4 +-- matlab/@dseries/save.m | 12 ++++----- matlab/@dseries/set_names.m | 4 +-- matlab/@dseries/subsasgn.m | 26 +++++++----------- matlab/@dseries/subsref.m | 16 +++++------ matlab/@dseries/tex_rename.m | 2 +- matlab/@dseries/uminus.m | 11 ++++---- matlab/@dseries/vertcat.m | 3 +-- matlab/@dseries/vobs.m | 22 +++++++++++++++ matlab/@dseries/ydiff.m | 8 +++--- matlab/@dseries/ygrowth.m | 8 +++--- 46 files changed, 282 insertions(+), 285 deletions(-) create mode 100644 matlab/@dseries/nobs.m create mode 100644 matlab/@dseries/vobs.m diff --git a/matlab/@dseries/abs.m b/matlab/@dseries/abs.m index 72a9520ce..ba4da3fab 100644 --- a/matlab/@dseries/abs.m +++ b/matlab/@dseries/abs.m @@ -40,16 +40,15 @@ function A = abs(B) % --*-- Unitary tests --*-- A = dseries(); -A.nobs = B.nobs; -A.vobs = B.vobs; +A.data = abs(B.data); A.dates = B.dates; -A.name = cell(A.vobs,1); -A.tex = cell(A.vobs,1); -for i = 1:A.vobs + +A.name = cell(vobs(A), 1); +A.tex = cell(vobs(A), 1); +for i = 1:vobs(A) A.name(i) = {[ 'abs(' B.name{i} ')']}; A.tex(i) = {[ '|' B.tex{i} '|']}; end -A.data = abs(B.data); %@test:1 %$ % Define a datasets. diff --git a/matlab/@dseries/align.m b/matlab/@dseries/align.m index e785e081d..32878127e 100644 --- a/matlab/@dseries/align.m +++ b/matlab/@dseries/align.m @@ -62,32 +62,28 @@ b_last = last; if firstdate(b)>init n = firstdate(b)-init; - b.data = [NaN(n,b.vobs); b.data]; - b.nobs = b.nobs+n; + b.data = [NaN(n, vobs(b)); b.data]; b_init = init; end if firstdate(a)>init n = firstdate(a)-init; - a.data = [NaN(n,a.vobs); a.data]; - a.nobs = a.nobs+n; + a.data = [NaN(n, vobs(a)); a.data]; a_init = init; end if lastdate(b). -if ts.vobs-us.vobs +if vobs(ts)-vobs(us) error(['dseries::chain: dseries objects ' inputname(1) ' and ' inputname(2) ' must have the same number of variables!']) end @@ -35,9 +35,8 @@ CumulatedGrowthFactors = cumprod(GrowthFactor); vs = ts; vs.data = [vs.data; bsxfun(@times,CumulatedGrowthFactors,vs.data(end,:))]; -vs.nobs = rows(vs.data); -vs.dates = firstdate(vs):firstdate(vs)+vs.nobs; +vs.dates = firstdate(vs):firstdate(vs)+nobs(vs); %@test:1 %$ try diff --git a/matlab/@dseries/check.m b/matlab/@dseries/check.m index a190b0dcc..c4bfce37a 100644 --- a/matlab/@dseries/check.m +++ b/matlab/@dseries/check.m @@ -21,7 +21,7 @@ error_flag = 0; [n,m] = size(A.data); -if ~isequal(m,A.vobs); +if ~isequal(m, vobs(A)); error_flag = 1; if nargout>1 message = ['dseries: Wrong number of variables in dseries object ''' inputname(1) '''!']; @@ -29,7 +29,7 @@ if ~isequal(m,A.vobs); return end -if ~isequal(n,A.nobs); +if ~isequal(n,nobs(A)); error_flag = 1; if nargout>1 message = ['dseries: Wrong number of observations in dseries object ''' inputname(1) '''!']; @@ -77,7 +77,7 @@ if ~isequal(numel(unique(A.tex)),numel(A.tex)); return end -if ~isequal(A.dates,firstdate(A):firstdate(A)+A.nobs) +if ~isequal(A.dates,firstdate(A):firstdate(A)+nobs(A)) error_flag = 1; if nargout>1 message = ['dseries: Wrong definition of the dates member in dseries object ''' inputname(1) '''!']; diff --git a/matlab/@dseries/cumprod.m b/matlab/@dseries/cumprod.m index 35ed8275e..4e98d38b1 100644 --- a/matlab/@dseries/cumprod.m +++ b/matlab/@dseries/cumprod.m @@ -34,7 +34,7 @@ if isempty(idx) error('dseries::cumprod: All the variables have NaNs. The cumulated product cannot be computed!') end -if ~isequal(idx(:),transpose(1:varargin{1}.vobs)) +if ~isequal(idx(:),transpose(1:vobs(varargin{1}))) warning('dseries::cumprod: The cumulated product is not computed for some variables because they have NaNs!') end @@ -45,19 +45,19 @@ switch nargin % Perform the cumulated sum B.data(:,idx) = cumprod(B.data(:,idx)); % Change the name of the variables - for i=1:B.vobs + 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(varargin{1}.vobs, varargin{2}.vobs) + if ~isequal(vobs(varargin{1}), vobs(varargin{2})) error('dseries::cumprod: First and second input arguments must be dseries objects with the same number of variables!') end if ~isequal(varargin{1}.name, varargin{2}.name) warning('dseries::cumprod: First and second input arguments must be dseries objects do not have the same variables!') end - if ~isequal(varargin{2}.nobs,1) + if ~isequal(nobs(varargin{2}),1) error('dseries::cumprod: Second input argument must be a dseries object with only one observation!') end B = cumprod(varargin{1}); @@ -84,13 +84,13 @@ switch nargin if ~isdseries(varargin{3}) error('dseries::cumprod: Third input argument must be a dseries object!') end - if ~isequal(varargin{1}.vobs, varargin{3}.vobs) + if ~isequal(vobs(varargin{1}), vobs(varargin{3})) error('dseries::cumprod: First and third input arguments must be dseries objects with the same number of variables!') end if ~isequal(varargin{1}.name, varargin{3}.name) warning('dseries::cumprod: First and third input arguments must be dseries objects do not have the same variables!') end - if ~isequal(varargin{3}.nobs,1) + if ~isequal(nobs(varargin{3}),1) error('dseries::cumprod: Third input argument must be a dseries object with only one observation!') end B = cumprod(varargin{1}); diff --git a/matlab/@dseries/cumsum.m b/matlab/@dseries/cumsum.m index 4c082c4ba..6dfb73c28 100644 --- a/matlab/@dseries/cumsum.m +++ b/matlab/@dseries/cumsum.m @@ -34,7 +34,7 @@ if isempty(idx) error('dseries::cumsum: All the variables have NaNs. The cumulated sum cannot be computed!') end -if ~isequal(idx(:),transpose(1:varargin{1}.vobs)) +if ~isequal(idx(:),transpose(1:vobs(varargin{1}))) warning('dseries::cumsum: The cumulated sum is not computed for some variables because they have NaNs!') end @@ -45,19 +45,19 @@ switch nargin % Perform the cumulated sum B.data(:,idx) = cumsum(B.data(:,idx)); % Change the name of the variables - for i=1:B.vobs + 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(varargin{1}.vobs, varargin{2}.vobs) + if ~isequal(vobs(varargin{1}), vobs(varargin{2})) error('dseries::cumsum: First and second input arguments must be dseries objects with the same number of variables!') end if ~isequal(varargin{1}.name, varargin{2}.name) warning('dseries::cumsum: First and second input arguments must be dseries objects do not have the same variables!') end - if ~isequal(varargin{2}.nobs,1) + if ~isequal(nobs(varargin{2}),1) error('dseries::cumsum: Second input argument must be a dseries object with only one observation!') end B = cumsum(varargin{1}); @@ -83,13 +83,13 @@ switch nargin if ~isdseries(varargin{3}) error('dseries::cumsum: Third input argument must be a dseries object!') end - if ~isequal(varargin{1}.vobs, varargin{3}.vobs) + if ~isequal(vobs(varargin{1}), vobs(varargin{3})) error('dseries::cumsum: First and third input arguments must be dseries objects with the same number of variables!') end if ~isequal(varargin{1}.name, varargin{3}.name) warning('dseries::cumsum: First and third input arguments must be dseries objects do not have the same variables!') end - if ~isequal(varargin{3}.nobs,1) + if ~isequal(nobs(varargin{3}),1) error('dseries::cumsum: Third input argument must be a dseries object with only one observation!') end B = cumsum(varargin{1}); diff --git a/matlab/@dseries/detrend.m b/matlab/@dseries/detrend.m index 04f8b023a..fa6a193f1 100644 --- a/matlab/@dseries/detrend.m +++ b/matlab/@dseries/detrend.m @@ -30,9 +30,9 @@ if isnumeric(model) case 0 data = demean(data); otherwise - x = NaN(o.nobs, model+1); - x(:,1) = ones(o.nobs, 1); - x(:,2) = transpose(1:o.nobs); + x = NaN(nobs(o), model+1); + x(:,1) = ones(nobs(o), 1); + x(:,2) = transpose(1:nobs(o)); for c=3:model+1 x(:,c) = x(:,c-1).*x(:,2); end diff --git a/matlab/@dseries/disp.m b/matlab/@dseries/disp.m index 4ea14a7e6..5bd38f464 100644 --- a/matlab/@dseries/disp.m +++ b/matlab/@dseries/disp.m @@ -19,16 +19,16 @@ function disp(A) %! @end deftypefn %@eod: -separator = repmat(' | ',A.nobs+1,1); +separator = repmat(' | ', nobs(A)+1,1); vspace = ' '; TABLE = ' '; -for t=1:A.nobs +for t=1:nobs(A) TABLE = char(TABLE, date2string(A.dates(t))); end -for i = 1:A.vobs +for i = 1:vobs(A) TABLE = horzcat(TABLE,separator); tmp = A.name{i}; - for t=1:A.nobs + for t=1:nobs(A) tmp = char(tmp,num2str(A.data(t,i))); end TABLE = horzcat(TABLE, tmp); diff --git a/matlab/@dseries/display.m b/matlab/@dseries/display.m index 70998ecd8..d6826a801 100644 --- a/matlab/@dseries/display.m +++ b/matlab/@dseries/display.m @@ -21,16 +21,16 @@ function display(A) vspace = ' '; TABLE = ' '; -if A.vobs<=10 - if A.nobs<=40 - separator = repmat(' | ',A.nobs+1,1); - for t=1:A.nobs +if vobs(A)<=10 + if nobs(A)<=40 + separator = repmat(' | ', nobs(A)+1,1); + for t=1:nobs(A) TABLE = char(TABLE, date2string(A.dates(t))); end - for i = 1:A.vobs + for i = 1:vobs(A) TABLE = horzcat(TABLE,separator); tmp = A.name{i}; - for t=1:A.nobs + for t=1:nobs(A) tmp = char(tmp,num2str(A.data(t,i))); end TABLE = horzcat(TABLE, tmp); @@ -42,17 +42,17 @@ if A.vobs<=10 TABLE = char(TABLE, date2string(A.dates(t))); end TABLE = char(TABLE,vspace); - for t = A.nobs-n:A.nobs + for t = nobs(A)-n:nobs(A) TABLE = char(TABLE, date2string(A.dates(t))); end - for i=1:A.vobs + for i=1:vobs(A) TABLE = horzcat(TABLE,separator); tmp = A.name{i}; for t=1:10 tmp = char(tmp,num2str(A.data(t,i))); end tmp = char(tmp,vspace); - for t=A.nobs-10:A.nobs + for t=nobs(A)-10:nobs(A) tmp = char(tmp,num2str(A.data(t,i))); end TABLE = horzcat(TABLE, tmp); @@ -60,24 +60,24 @@ if A.vobs<=10 end else m = 4; - if A.nobs<=40 - separator = repmat(' | ',A.nobs+1,1); - for t=1:A.nobs + if nobs(A)<=40 + separator = repmat(' | ', nobs(A)+1,1); + for t=1:nobs(A) TABLE = char(TABLE, date2string(A.dates(t))); end for i = 1:m TABLE = horzcat(TABLE,separator); tmp = A.name{i}; - for t=1:A.nobs + for t=1:nobs(A) tmp = char(tmp,num2str(A.data(t,i))); end TABLE = horzcat(TABLE, tmp); end - TABLE = horzcat(TABLE, separator, repmat(' ... ', A.nobs+1,1)); - for i = A.vobs-m+1:A.vobs + TABLE = horzcat(TABLE, separator, repmat(' ... ', nobs(A)+1,1)); + for i = vobs(A)-m+1:vobs(A) TABLE = horzcat(TABLE,separator); tmp = A.name{i}; - for t=1:A.nobs + for t=1:nobs(A) tmp = char(tmp,num2str(A.data(t,i))); end TABLE = horzcat(TABLE, tmp); @@ -89,7 +89,7 @@ else TABLE = char(TABLE, date2string(A.dates(t))); end TABLE = char(TABLE,vspace); - for t = A.nobs-n:A.nobs + for t = nobs(A)-n:nobs(A) TABLE = char(TABLE, date2string(A.dates(t))); end for i=1:m @@ -99,20 +99,20 @@ else tmp = char(tmp,num2str(A.data(t,i))); end tmp = char(tmp,vspace); - for t=A.nobs-10:A.nobs + for t=nobs(A)-10:nobs(A) tmp = char(tmp,num2str(A.data(t,i))); end TABLE = horzcat(TABLE, tmp); end TABLE = horzcat(TABLE, separator, repmat(' ... ', 2*n+3,1)); - for i=A.vobs-m+1:A.vobs + for i=vobs(A)-m+1:vobs(A) TABLE = horzcat(TABLE,separator); tmp = A.name{i}; for t=1:10 tmp = char(tmp,num2str(A.data(t,i))); end tmp = char(tmp,vspace); - for t=A.nobs-10:A.nobs + for t=nobs(A)-10:nobs(A) tmp = char(tmp,num2str(A.data(t,i))); end TABLE = horzcat(TABLE, tmp); diff --git a/matlab/@dseries/dseries.m b/matlab/@dseries/dseries.m index bd5273a1d..7fadb4c43 100644 --- a/matlab/@dseries/dseries.m +++ b/matlab/@dseries/dseries.m @@ -79,8 +79,6 @@ function ts = dseries(varargin) % --*-- Unitary tests --*-- if nargin>0 && ischar(varargin{1}) && isequal(varargin{1},'initialize') ts = struct; ts.data = []; - ts.nobs = 0; - ts.vobs = 0; ts.name = {}; ts.tex = {}; ts.dates = dates(); @@ -137,9 +135,7 @@ switch nargin end ts.data = data; ts.name = varlist; - ts.vobs = length(varlist); - ts.nobs = size(data,1); - ts.dates = init:init+(ts.nobs-1); + ts.dates = init:init+(nobs(ts)-1); if isempty(tex) ts.tex = name2tex(varlist); else @@ -147,10 +143,9 @@ switch nargin end elseif isnumeric(varargin{1}) && isequal(ndims(varargin{1}),2) ts.data = varargin{1}; - [ts.nobs, ts.vobs] = size(ts.data); - ts.name = default_name(ts.vobs); + ts.name = default_name(vobs(ts)); ts.tex = name2tex(ts.name); - ts.dates = dates(1,1):dates(1,1)+(ts.nobs-1); + ts.dates = dates(1,1):dates(1,1)+(nobs(ts)-1); end case {2,3,4} if isequal(nargin,2) && ischar(varargin{1}) && isdates(varargin{2}) @@ -185,29 +180,26 @@ switch nargin end % Get data, number of observations and number of variables. ts.data = a; - ts.nobs = size(a,1); - ts.vobs = size(a,2); % Get the first date and set the frequency. if isempty(b) init = dates(1,1); elseif (isdates(b) && isequal(length(b),1)) init = b; - elseif isdate(b)% Weekly, Monthly, Quaterly or Annual data (string). + elseif ischar(b) && isdate(b)% Weekly, Monthly, Quaterly or Annual data (string). init = dates(b); elseif (isnumeric(b) && isscalar(b) && isint(b)) % Yearly data. init = dates([num2str(b) 'Y']); elseif isdates(b) % Range of dates init = b(1); - if ts.nobs>1 && ~isequal(b.ndat,ts.nobs) + if nobs(ts)>1 && ~isequal(b.ndat,nobs(ts)) message = 'dseries::dseries: If second input is a range, its number of elements must match '; message = char(message, ' the number of rows in the first input, unless the first input'); message = char(message, ' has only one row.'); skipline() disp(message); error(' '); - elseif isequal(ts.nobs, 1) + elseif isequal(nobs(ts), 1) ts.data = repmat(ts.data,b.ndat,1); - ts.nobs = b.ndat; end ts.dates = b; elseif (isnumeric(b) && isint(b)) % Range of yearly dates. @@ -220,19 +212,19 @@ switch nargin end % Get the names of the variables. if ~isempty(c) - if ts.vobs==length(c) - for i=1:ts.vobs + if vobs(ts)==length(c) + for i=1:vobs(ts) ts.name = vertcat(ts.name, c(i)); end else error('dseries::dseries: The number of declared names does not match the number of variables!') end else - ts.name = default_name(ts.vobs); + ts.name = default_name(vobs(ts)); end if ~isempty(d) - if ts.vobs==length(d) - for i=1:ts.vobs + if vobs(ts)==length(d) + for i=1:vobs(ts) ts.tex = vertcat(ts.tex, d(i)); end else @@ -246,7 +238,7 @@ switch nargin end if isempty(ts.dates) - ts.dates = init:init+(ts.nobs-1); + ts.dates = init:init+(nobs(ts)-1); end %@test:1 @@ -349,12 +341,12 @@ end %@test:6 %$ t = zeros(8,1); %$ -%$ %try +%$ try %$ ts = dseries(transpose(1:5),[]); %$ t(1) = 1; -%$ %catch -%$ % t = 0; -%$ %end +%$ catch +%$ t = 0; +%$ end %$ %$ if length(t)>1 %$ t(2) = dyn_assert(ts.freq,1); diff --git a/matlab/@dseries/end.m b/matlab/@dseries/end.m index a90869288..8f6097136 100644 --- a/matlab/@dseries/end.m +++ b/matlab/@dseries/end.m @@ -18,4 +18,4 @@ function lastIndex = end(o, k, n) % along with Dynare. If not, see . assert(k==1 && n==1, 'dseries::end: Wrong indexing!'); -lastIndex = o.vobs; \ No newline at end of file +lastIndex = vobs(o); \ No newline at end of file diff --git a/matlab/@dseries/eq.m b/matlab/@dseries/eq.m index 7dcd86b2a..7664cb094 100644 --- a/matlab/@dseries/eq.m +++ b/matlab/@dseries/eq.m @@ -37,13 +37,13 @@ if ~(isdseries(A) && isdseries(B)) error('dseries::eq: Both input arguments must be dseries objects!') end -if ~isequal(A.nobs,B.nobs) +if ~isequal(nobs(A), nobs(B)) warning('dseries::eq: Both input arguments should have the same number of observations!') C = 0; return end -if ~isequal(A.vobs,B.vobs) +if ~isequal(vobs(A), vobs(B)) warning('dseries::eq: Both input arguments should have the same number of observations!') C = 0; return diff --git a/matlab/@dseries/exp.m b/matlab/@dseries/exp.m index 4fa36bc79..06ed6a1f0 100644 --- a/matlab/@dseries/exp.m +++ b/matlab/@dseries/exp.m @@ -46,7 +46,7 @@ function ts = exp(ts) ts.data = exp(ts.data); -for i=1:ts.vobs +for i=1:vobs(ts) ts.name(i) = {['exp(' ts.name{i} ')']}; ts.tex(i) = {['\exp(' ts.tex{i} ')']}; end \ No newline at end of file diff --git a/matlab/@dseries/extract.m b/matlab/@dseries/extract.m index 2d61a0b95..c280115ee 100644 --- a/matlab/@dseries/extract.m +++ b/matlab/@dseries/extract.m @@ -126,8 +126,6 @@ end A.data = B.data(:,idVariableName); A.dates = B.dates; -A.nobs = B.nobs; -A.vobs = length(idVariableName); A.name = B.name(idVariableName); A.tex = B.tex(idVariableName); diff --git a/matlab/@dseries/horzcat.m b/matlab/@dseries/horzcat.m index 5f05af87f..e4d9cbee7 100644 --- a/matlab/@dseries/horzcat.m +++ b/matlab/@dseries/horzcat.m @@ -68,41 +68,38 @@ function a = concatenate(b,c) a = dseries(); end d_nobs_flag = 0; - if ~isequal(b.nobs,c.nobs) + if ~isequal(nobs(b),nobs(c)) d_nobs_flag = 1; - else - a.nobs = b.nobs; end d_init_flag = 0; if ~isequal(firstdate(b),firstdate(c)) d_init_flag = 1; end - a.vobs = b.vobs+c.vobs; 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)c_last_date - c.data = [c.data; NaN(b_last_date-c_last_date,c.vobs)]; + c.data = [c.data; NaN(b_last_date-c_last_date, vobs(c))]; end a.data = [b.data, c.data]; a.dates = unique([b.dates, c.dates]); end - a.nobs = size(a.data,1); %@test:1 %$ % Define a data set. diff --git a/matlab/@dseries/hpcycle.m b/matlab/@dseries/hpcycle.m index a35abf7b6..ad1ec56fa 100644 --- a/matlab/@dseries/hpcycle.m +++ b/matlab/@dseries/hpcycle.m @@ -36,7 +36,7 @@ else lambda = []; end -for i=1:ts.vobs +for i=1:vobs(ts) ts.name(i) = {['hpcycle(' ts.name{i} ')']}; ts.tex(i) = {['\text{hpcycle}(' ts.tex{i} ')']}; end diff --git a/matlab/@dseries/hptrend.m b/matlab/@dseries/hptrend.m index a8e1366b7..754b3212a 100644 --- a/matlab/@dseries/hptrend.m +++ b/matlab/@dseries/hptrend.m @@ -36,7 +36,7 @@ else lambda = []; end -for i=1:ts.vobs +for i=1:vobs(ts) ts.name(i) = {['hptrend(' ts.name{i} ')']}; ts.tex(i) = {['\text{hptrend}(' ts.tex{i} ')']}; end diff --git a/matlab/@dseries/insert.m b/matlab/@dseries/insert.m index 128c72dff..e15508614 100644 --- a/matlab/@dseries/insert.m +++ b/matlab/@dseries/insert.m @@ -74,11 +74,6 @@ for i=1:n id = id+1; end -% Update vobs member. -ts.vobs = columns(ts.data); - - - %@test:1 %$ % Define a datasets. %$ A = rand(10,3); B = rand(5,2); diff --git a/matlab/@dseries/isempty.m b/matlab/@dseries/isempty.m index f171be295..5df634e46 100644 --- a/matlab/@dseries/isempty.m +++ b/matlab/@dseries/isempty.m @@ -36,5 +36,5 @@ function b = isempty(A) % % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . - -b = isempty(A.data) && isequal(A.nobs,0) && isequal(A.vobs,0); \ No newline at end of file + +b = isempty(A.data); \ No newline at end of file diff --git a/matlab/@dseries/isequal.m b/matlab/@dseries/isequal.m index 003f6903c..d57150551 100644 --- a/matlab/@dseries/isequal.m +++ b/matlab/@dseries/isequal.m @@ -34,12 +34,12 @@ if ~isdseries(B) error('dseries::isequal: Both input arguments must be dseries objects!') end -if ~isequal(A.nobs,B.nobs) +if ~isequal(nobs(A), nobs(B)) C = 0; return end -if ~isequal(A.vobs,B.vobs) +if ~isequal(vobs(A), vobs(B)) C = 0; return end diff --git a/matlab/@dseries/lag.m b/matlab/@dseries/lag.m index d0ce3965d..4a2069599 100644 --- a/matlab/@dseries/lag.m +++ b/matlab/@dseries/lag.m @@ -52,9 +52,9 @@ end us = ts; % Update data member -us.data = [NaN(p,ts.vobs); ts.data(1:end-p,:)]; +us.data = [NaN(p, vobs(ts)); ts.data(1:end-p,:)]; -for i=1:ts.vobs +for i=1:vobs(ts) us.name(i) = {[ 'lag(' ts.name{i} ',' int2str(p) ')']}; us.tex(i) = {[ ts.tex{i} '_{-' int2str(p) '}']}; end diff --git a/matlab/@dseries/lead.m b/matlab/@dseries/lead.m index 8a61e2d0c..c4eba7a23 100644 --- a/matlab/@dseries/lead.m +++ b/matlab/@dseries/lead.m @@ -52,9 +52,9 @@ end us = ts; % Update data member -us.data = [ ts.data(p+1:end,:); NaN(p,ts.vobs);]; +us.data = [ ts.data(p+1:end,:); NaN(p, vobs(ts));]; -for i=1:ts.vobs +for i=1:vobs(ts) us.name(i) = {[ 'lead(' ts.name{i} ',' int2str(p) ')']}; us.tex(i) = {[ ts.tex{i} '_{+' int2str(p) '}']}; end diff --git a/matlab/@dseries/log.m b/matlab/@dseries/log.m index 6655fa29a..2ff8e6488 100644 --- a/matlab/@dseries/log.m +++ b/matlab/@dseries/log.m @@ -47,7 +47,7 @@ if any(ts.data= firstdate(C) diff = firstdate(B) - firstdate(C); - A.nobs = max(B.nobs + diff, C.nobs); - A.data = NaN(A.nobs, A.vobs); - Z1 = [NaN(diff,B.vobs);B.data]; - if A.nobs > B.nobs + diff - Z1 = [Z1; NaN(A.nobs-(B.nobs + diff),B.vobs)]; + A_nobs = max(nobs(B) + diff, nobs(C)); + A.data = NaN(A_nobs, vobs(A)); + Z1 = [NaN(diff, vobs(B));B.data]; + if nobs(A) > nobs(B) + diff + Z1 = [Z1; NaN(nobs(A)-(nobs(B) + diff), vobs(B))]; end; Z2 = C.data; - if A.nobs > C.nobs - Z2 = [Z2; NaN(A.nobs - C.nobs,C.vobs)]; + if nobs(A) > nobs(C) + Z2 = [Z2; NaN(nobs(A) - nobs(C), vobs(C))]; end; Z = [Z1 Z2]; A.data = Z(:,IBC); A_init = firstdate(C); else diff = firstdate(C) - firstdate(B); - A.nobs = max(C.nobs + diff, B.nobs); - A.data = NaN(A.nobs, A.vobs); - Z1 = [NaN(diff,C.vobs);C.data]; - if A.nobs > C.nobs + diff - Z1 = [Z1; NaN(A.nobs-(C.nobs + diff),C.vobs)]; - end; + A_nobs = max(nobs(C) + diff, nobs(B)); + A.data = NaN(A_nobs, vobs(A)); + Z1 = [NaN(diff, vobs(C)); C.data]; + if nobs(A) > nobs(C) + diff + Z1 = [Z1; NaN(nobs(A)-(nobs(C) + diff), vobs(C))]; + end Z2 = B.data; - if A.nobs > B.nobs - Z2 = [Z2; NaN(A.nobs - B.nobs,B.vobs)]; + if nobs(A) > nobs(B) + Z2 = [Z2; NaN(nobs(A) - nobs(B), vobs(B))]; end; Z = [Z2 Z1]; A.data = Z(:,IBC); A_init = B.init; end -A.dates = A_init:A_init+(A.nobs-1); +A.dates = A_init:A_init+(nobs(A)-1); %@test:1 %$ % Define a datasets. diff --git a/matlab/@dseries/minus.m b/matlab/@dseries/minus.m index ec9bf419a..a6b6f91e4 100644 --- a/matlab/@dseries/minus.m +++ b/matlab/@dseries/minus.m @@ -58,18 +58,18 @@ if isnumeric(C) && (isscalar(C) || isvector(C)) return end -if ~isequal(B.vobs,C.vobs) && ~(isequal(B.vobs,1) || isequal(C.vobs,1)) +if ~isequal(vobs(B), vobs(C)) && ~(isequal(vobs(B),1) || isequal(vobs(C),1)) error(['dseries::minus: Cannot substract ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!']) else - if B.vobs>C.vobs - idB = 1:B.vobs; - idC = ones(1:B.vobs); - elseif B.vobsvobs(C) + idB = 1:vobs(B); + idC = ones(1:vobs(B)); + elseif vobs(B)C.vobs - idB = 1:B.vobs; - idC = ones(1:B.vobs); - elseif B.vobsvobs(C) + idB = 1:vobs(B); + idC = ones(1:vobs(B)); + elseif vobs(B)C.vobs - idB = 1:B.vobs; - idC = ones(1:B.vobs); - elseif B.vobsvobs(C) + idB = 1:vobs(B); + idC = ones(1:vobs(B)); + elseif vobs(B). + +s = rows(ts.data); \ No newline at end of file diff --git a/matlab/@dseries/plot.m b/matlab/@dseries/plot.m index 26d8e80d0..058a44dd0 100644 --- a/matlab/@dseries/plot.m +++ b/matlab/@dseries/plot.m @@ -22,26 +22,26 @@ function h = plot(ts, varargin) % Get the number of dseries objects if isequal(nargin,1) ndseries = 1; - nvariables = ts.vobs; - nobservations = ts.nobs; + nvariables = vobs(ts); + nobservations = nobs(ts); else if isdseries(varargin{1}) ndseries = 2; - nvariables = ts.vobs; - nobservations = ts.nobs; + nvariables = vobs(ts); + nobservations = nobs(ts); if nargin>2 && any(cellfun(@isdseries,varargin(2:end))) error('dseries::plot: You cannot pass more two dseries objects!') end - if ~isequal(nvariables,varargin{1}.vobs) + if ~isequal(nvariables, vobs(varargin{1})) error('dseries::plot: The two dseries objects must have the same number of variables!') end - if ~isequal(nobservations,varargin{1}.nobs) + if ~isequal(nobservations, nobs(varargin{1})) error('dseries::plot: The two dseries objects must have the same number of observations!') end else ndseries = 1; - nvariables = ts.vobs; - nobservations = ts.nobs; + nvariables = vobs(ts); + nobservations = nobs(ts); end end diff --git a/matlab/@dseries/plus.m b/matlab/@dseries/plus.m index 9f2ba1eb5..ee3f0295c 100644 --- a/matlab/@dseries/plus.m +++ b/matlab/@dseries/plus.m @@ -58,18 +58,18 @@ if isnumeric(C) && (isscalar(C) || isvector(C)) return end -if ~isequal(B.vobs,C.vobs) && ~(isequal(B.vobs,1) || isequal(C.vobs,1)) +if ~isequal(vobs(B), vobs(C)) && ~(isequal(vobs(B), 1) || isequal(vobs(C), 1)) error(['dseries::plus: Cannot add ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!']) else - if B.vobs>C.vobs - idB = 1:B.vobs; - idC = ones(1,B.vobs); - elseif B.vobsvobs(C) + idB = 1:vobs(B); + idC = ones(1,vobs(B)); + elseif vobs(B)1 && isequal(S(2).type,'()') && isempty(S(2).subs) error(['dseries::subsref: ' S(1).subs ' is not a method but a member!']) end @@ -75,6 +75,12 @@ switch S(1).type if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs) S = shiftS(S,1); end + case 'nobs' + % Returns the number of observations. + B = rows(A.data); + case 'vobs' + % Returns the number of variables. + B = columns(A.data); case 'init' % Returns a dates object (first date). B = A.dates(1); @@ -177,8 +183,6 @@ switch S(1).type B.name = A.name(ndx); B.tex = A.tex(ndx); B.tex = deblank(A.tex(ndx,:)); - B.nobs = A.nobs; - B.vobs = 1; B.dates = A.dates; else error('dseries::subsref: Unknown public method, public member or variable!') @@ -232,8 +236,6 @@ switch S(1).type B.data = A.data(tdx,:); B.name = A.name; B.tex = A.tex; - B.nobs = length(tdx); - B.vobs = A.vobs; B.dates = A.dates(tdx); elseif isvector(S(1).subs{1}) && all(isint(S(1).subs{1})) error('dseries::subsref: It is not possible to select observations with a vector of integers. You have to index with a dates object instead!'); @@ -245,15 +247,13 @@ switch S(1).type B = extract(A,S(1).subs{:}); elseif isequal(length(S(1).subs),1) && all(isint(S(1).subs{1})) idx = S(1).subs{1}; - if max(idx)>A.vobs || min(idx)<1 + if max(idx)>size(A.data,2) || min(idx)<1 error('dseries::subsref: Indices are out of bounds!') end B = dseries(); B.data = A.data(:,idx); B.name = A.name(idx); B.tex = A.tex(idx); - B.nobs = A.nobs; - B.vobs = length(idx); B.dates = A.dates; else error('dseries::subsref: What the Hell are you tryin'' to do?!') diff --git a/matlab/@dseries/tex_rename.m b/matlab/@dseries/tex_rename.m index ae9975507..86e3bf974 100644 --- a/matlab/@dseries/tex_rename.m +++ b/matlab/@dseries/tex_rename.m @@ -21,7 +21,7 @@ assert(nargin <= 3, 'dseries::tex_rename: accepts at most three args'); if nargin == 2 newtexname = varargin{1}; - assert(ts.vobs == 1, ['dseries::tex_rename: with one argument, the dseries contain only one variable.']); + assert(vobs(ts) == 1, ['dseries::tex_rename: with one argument, the dseries contain only one variable.']); else newtexname = varargin{2}; name = varargin{1}; diff --git a/matlab/@dseries/uminus.m b/matlab/@dseries/uminus.m index e8214cd59..000fbda74 100644 --- a/matlab/@dseries/uminus.m +++ b/matlab/@dseries/uminus.m @@ -42,16 +42,15 @@ function A = uminus(B) % --*-- Unitary tests --*-- A = dseries(); -A.nobs = B.nobs; -A.vobs = B.vobs; +A.data = -(B.data); A.dates = B.dates; -A.name = cell(A.vobs,1); -A.tex = cell(A.vobs,1); -for i = 1:A.vobs + +A.name = cell(vobs(A),1); +A.tex = cell(vobs(A),1); +for i = 1:vobs(A) A.name(i) = {[ '-' B.name{i}]}; A.tex(i) = {[ '-' B.tex{i}]}; end -A.data = -(B.data); %@test:1 %$ % Define a datasets. diff --git a/matlab/@dseries/vertcat.m b/matlab/@dseries/vertcat.m index 4b4a680fe..ad2af8b07 100644 --- a/matlab/@dseries/vertcat.m +++ b/matlab/@dseries/vertcat.m @@ -63,7 +63,7 @@ function d = vertcat_(b, c) if ~isequal(frequency(b), frequency(c)) error('dseries::vertcat: Frequencies must be common!') end - if ~isequal(b.vobs, c.vobs) + if ~isequal(vobs(b), vobs(c)) error('dseries::vertcat: Number of variables must be common!') end if ~isequal(b.name, c.name) @@ -72,7 +72,6 @@ function d = vertcat_(b, c) d = b; d.data = [b.data; c.data]; d.dates = [b.dates; c.dates]; - d.nobs = b.nobs+c.nobs; %@test:1 %$ % Define a data set. diff --git a/matlab/@dseries/vobs.m b/matlab/@dseries/vobs.m new file mode 100644 index 000000000..37c1c80dd --- /dev/null +++ b/matlab/@dseries/vobs.m @@ -0,0 +1,22 @@ +function s = vobs(ts) + +% Returns the number of variables in a @dseries object. + +% Copyright (C) 2014 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see . + +s = columns(ts.data); \ No newline at end of file diff --git a/matlab/@dseries/ydiff.m b/matlab/@dseries/ydiff.m index beee58c8a..d50200b57 100644 --- a/matlab/@dseries/ydiff.m +++ b/matlab/@dseries/ydiff.m @@ -45,28 +45,28 @@ switch frequency(ts) case 1 us.data(2:end,:) = ts.data(2:end,:)-ts.data(1:end-1,:); us.data(1,:) = NaN; - for i = 1:ts.vobs + for i = 1:vobs(ts) us.name(i) = {['ydiff(' us.name{i} ')']}; us.tex(i) = {['\Delta ' us.tex{i}]}; end case 4 us.data(5:end,:) = ts.data(5:end,:)-ts.data(1:end-4,:); us.data(1:4,:) = NaN; - for i = 1:ts.vobs + for i = 1:vobs(ts) us.name(i) = {['ydiff(' us.name{i} ')']}; us.tex(i) = {['\Delta_4 ' us.tex{i}]}; end case 12 us.data(13:end,:) = ts.data(13:end,:)-ts.data(1:end-12,:); us.data(1:12,:) = NaN; - for i = 1:ts.vobs + for i = 1:vobs(ts) us.name(i) = {['ydiff(' us.name{i} ')']}; us.tex(i) = {['\Delta_{12} ' us.tex{i}]}; end case 52 us.data(53:end,:) = ts.data(53:end,:)-ts.data(1:end-52,:); us.data(1:52,:) = NaN; - for i = 1:ts.vobs + for i = 1:vobs(ts) us.name(i) = {['ydiff(' us.name{i} ')']}; us.tex(i) = {['\Delta_{52} ' us.tex{i}]}; end diff --git a/matlab/@dseries/ygrowth.m b/matlab/@dseries/ygrowth.m index ba988ec2e..9b50c38c9 100644 --- a/matlab/@dseries/ygrowth.m +++ b/matlab/@dseries/ygrowth.m @@ -45,28 +45,28 @@ switch frequency(ts) case 1 us.data(2:end,:) = ts.data(2:end,:)./ts.data(1:end-1,:) - 1; us.data(1,:) = NaN; - for i = 1:ts.vobs + for i = 1:vobs(ts) us.name(i) = {['ygrowth(' us.name{i} ')']}; us.tex(i) = {['\delta ' us.tex{i}]}; end case 4 us.data(5:end,:) = ts.data(5:end,:)./ts.data(1:end-4,:) - 1; us.data(1:4,:) = NaN; - for i = 1:ts.vobs + for i = 1:vobs(ts) us.name(i) = {['ygrowth(' us.name{i} ')']}; us.tex(i) = {['\delta_4 ' us.tex{i}]}; end case 12 us.data(13:end,:) = ts.data(13:end,:)./ts.data(1:end-12,:) - 1; us.data(1:12,:) = NaN; - for i = 1:ts.vobs + for i = 1:vobs(ts) us.name(i) = {['ygrowth(' us.name{i} ')']}; us.tex(i) = {['\delta_{12} ' us.tex{i}]}; end case 52 us.data(53:end,:) = ts.data(53:end,:)./ts.data(1:end-52,:) - 1; us.data(1:52,:) = NaN; - for i = 1:ts.vobs + for i = 1:vobs(ts) us.name(i) = {['ygrowth(' us.name{i} ')']}; us.tex(i) = {['\delta_{52} ' us.tex{i}]}; end