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.
time-shift
Stéphane Adjemian (Scylla) 2014-07-28 17:48:49 +02:00
parent 555e2cf73b
commit c5af1d43ed
46 changed files with 282 additions and 285 deletions

View File

@ -40,16 +40,15 @@ function A = abs(B) % --*-- Unitary tests --*--
A = dseries(); A = dseries();
A.nobs = B.nobs; A.data = abs(B.data);
A.vobs = B.vobs;
A.dates = B.dates; A.dates = B.dates;
A.name = cell(A.vobs,1);
A.tex = cell(A.vobs,1); A.name = cell(vobs(A), 1);
for i = 1:A.vobs A.tex = cell(vobs(A), 1);
for i = 1:vobs(A)
A.name(i) = {[ 'abs(' B.name{i} ')']}; A.name(i) = {[ 'abs(' B.name{i} ')']};
A.tex(i) = {[ '|' B.tex{i} '|']}; A.tex(i) = {[ '|' B.tex{i} '|']};
end end
A.data = abs(B.data);
%@test:1 %@test:1
%$ % Define a datasets. %$ % Define a datasets.

View File

@ -62,32 +62,28 @@ b_last = last;
if firstdate(b)>init if firstdate(b)>init
n = firstdate(b)-init; n = firstdate(b)-init;
b.data = [NaN(n,b.vobs); b.data]; b.data = [NaN(n, vobs(b)); b.data];
b.nobs = b.nobs+n;
b_init = init; b_init = init;
end end
if firstdate(a)>init if firstdate(a)>init
n = firstdate(a)-init; n = firstdate(a)-init;
a.data = [NaN(n,a.vobs); a.data]; a.data = [NaN(n, vobs(a)); a.data];
a.nobs = a.nobs+n;
a_init = init; a_init = init;
end end
if lastdate(b)<last if lastdate(b)<last
n = last-lastdate(b); n = last-lastdate(b);
b.data = [b.data; NaN(n,b.vobs)]; b.data = [b.data; NaN(n, vobs(b))];
b.nobs = b.nobs+n;
end end
if lastdate(a)<last if lastdate(a)<last
n = last-lastdate(a); n = last-lastdate(a);
a.data = [a.data; NaN(n,a.vobs)]; a.data = [a.data; NaN(n, vobs(a))];
a.nobs = a.nobs+n;
end end
a.dates = a_init:a_init+(a.nobs-1); a.dates = a_init:a_init+(nobs(a)-1);
b.dates = b_init:b_init+(b.nobs-1); b.dates = b_init:b_init+(nobs(b)-1);
%@test:1 %@test:1
%$ % Define a datasets. %$ % Define a datasets.

View File

@ -87,15 +87,14 @@ weights = [flipud(weights(2:K+1)); weights];
tmp = zeros(size(ts.data)); tmp = zeros(size(ts.data));
% Filtering step. % Filtering step.
for t = K+1:ts.nobs-K 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 end
% Update dseries object. % Update dseries object.
ts.data = tmp(K+1:end-K,:); ts.data = tmp(K+1:end-K,:);
ts.nobs = ts.nobs-2*K;
init = firstdate(ts)+K; init = firstdate(ts)+K;
ts.dates = init:init+(ts.nobs-1); ts.dates = init:init+(nobs(ts)-1);
%@test:1 %@test:1
%$ plot_flag = 0; %$ plot_flag = 0;

View File

@ -17,7 +17,7 @@ function vs = chain(ts,us) % --*-- Unitary tests --*--
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
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!']) error(['dseries::chain: dseries objects ' inputname(1) ' and ' inputname(2) ' must have the same number of variables!'])
end end
@ -35,9 +35,8 @@ CumulatedGrowthFactors = cumprod(GrowthFactor);
vs = ts; vs = ts;
vs.data = [vs.data; bsxfun(@times,CumulatedGrowthFactors,vs.data(end,:))]; 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 %@test:1
%$ try %$ try

View File

@ -21,7 +21,7 @@ error_flag = 0;
[n,m] = size(A.data); [n,m] = size(A.data);
if ~isequal(m,A.vobs); if ~isequal(m, vobs(A));
error_flag = 1; error_flag = 1;
if nargout>1 if nargout>1
message = ['dseries: Wrong number of variables in dseries object ''' inputname(1) '''!']; message = ['dseries: Wrong number of variables in dseries object ''' inputname(1) '''!'];
@ -29,7 +29,7 @@ if ~isequal(m,A.vobs);
return return
end end
if ~isequal(n,A.nobs); if ~isequal(n,nobs(A));
error_flag = 1; error_flag = 1;
if nargout>1 if nargout>1
message = ['dseries: Wrong number of observations in dseries object ''' inputname(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 return
end end
if ~isequal(A.dates,firstdate(A):firstdate(A)+A.nobs) if ~isequal(A.dates,firstdate(A):firstdate(A)+nobs(A))
error_flag = 1; error_flag = 1;
if nargout>1 if nargout>1
message = ['dseries: Wrong definition of the dates member in dseries object ''' inputname(1) '''!']; message = ['dseries: Wrong definition of the dates member in dseries object ''' inputname(1) '''!'];

View File

@ -34,7 +34,7 @@ if isempty(idx)
error('dseries::cumprod: All the variables have NaNs. The cumulated product cannot be computed!') error('dseries::cumprod: All the variables have NaNs. The cumulated product cannot be computed!')
end 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!') warning('dseries::cumprod: The cumulated product is not computed for some variables because they have NaNs!')
end end
@ -45,19 +45,19 @@ switch nargin
% Perform the cumulated sum % Perform the cumulated sum
B.data(:,idx) = cumprod(B.data(:,idx)); B.data(:,idx) = cumprod(B.data(:,idx));
% Change the name of the variables % Change the name of the variables
for i=1:B.vobs for i=1:vobs(B)
B.name(i) = {['cumprod(' B.name{i} ')']}; B.name(i) = {['cumprod(' B.name{i} ')']};
B.tex(i) = {['\prod_t ' B.tex{i}]}; B.tex(i) = {['\prod_t ' B.tex{i}]};
end end
case 2 case 2
if isdseries(varargin{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!') error('dseries::cumprod: First and second input arguments must be dseries objects with the same number of variables!')
end end
if ~isequal(varargin{1}.name, varargin{2}.name) 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!') warning('dseries::cumprod: First and second input arguments must be dseries objects do not have the same variables!')
end 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!') error('dseries::cumprod: Second input argument must be a dseries object with only one observation!')
end end
B = cumprod(varargin{1}); B = cumprod(varargin{1});
@ -84,13 +84,13 @@ switch nargin
if ~isdseries(varargin{3}) if ~isdseries(varargin{3})
error('dseries::cumprod: Third input argument must be a dseries object!') error('dseries::cumprod: Third input argument must be a dseries object!')
end 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!') error('dseries::cumprod: First and third input arguments must be dseries objects with the same number of variables!')
end end
if ~isequal(varargin{1}.name, varargin{3}.name) 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!') warning('dseries::cumprod: First and third input arguments must be dseries objects do not have the same variables!')
end 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!') error('dseries::cumprod: Third input argument must be a dseries object with only one observation!')
end end
B = cumprod(varargin{1}); B = cumprod(varargin{1});

View File

@ -34,7 +34,7 @@ if isempty(idx)
error('dseries::cumsum: All the variables have NaNs. The cumulated sum cannot be computed!') error('dseries::cumsum: All the variables have NaNs. The cumulated sum cannot be computed!')
end 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!') warning('dseries::cumsum: The cumulated sum is not computed for some variables because they have NaNs!')
end end
@ -45,19 +45,19 @@ switch nargin
% Perform the cumulated sum % Perform the cumulated sum
B.data(:,idx) = cumsum(B.data(:,idx)); B.data(:,idx) = cumsum(B.data(:,idx));
% Change the name of the variables % Change the name of the variables
for i=1:B.vobs for i=1:vobs(B)
B.name(i) = {['cumsum(' B.name{i} ')']}; B.name(i) = {['cumsum(' B.name{i} ')']};
B.tex(i) = {['\sum_t ' B.tex{i}]}; B.tex(i) = {['\sum_t ' B.tex{i}]};
end end
case 2 case 2
if isdseries(varargin{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!') error('dseries::cumsum: First and second input arguments must be dseries objects with the same number of variables!')
end end
if ~isequal(varargin{1}.name, varargin{2}.name) 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!') warning('dseries::cumsum: First and second input arguments must be dseries objects do not have the same variables!')
end 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!') error('dseries::cumsum: Second input argument must be a dseries object with only one observation!')
end end
B = cumsum(varargin{1}); B = cumsum(varargin{1});
@ -83,13 +83,13 @@ switch nargin
if ~isdseries(varargin{3}) if ~isdseries(varargin{3})
error('dseries::cumsum: Third input argument must be a dseries object!') error('dseries::cumsum: Third input argument must be a dseries object!')
end 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!') error('dseries::cumsum: First and third input arguments must be dseries objects with the same number of variables!')
end end
if ~isequal(varargin{1}.name, varargin{3}.name) 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!') warning('dseries::cumsum: First and third input arguments must be dseries objects do not have the same variables!')
end 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!') error('dseries::cumsum: Third input argument must be a dseries object with only one observation!')
end end
B = cumsum(varargin{1}); B = cumsum(varargin{1});

View File

@ -30,9 +30,9 @@ if isnumeric(model)
case 0 case 0
data = demean(data); data = demean(data);
otherwise otherwise
x = NaN(o.nobs, model+1); x = NaN(nobs(o), model+1);
x(:,1) = ones(o.nobs, 1); x(:,1) = ones(nobs(o), 1);
x(:,2) = transpose(1:o.nobs); x(:,2) = transpose(1:nobs(o));
for c=3:model+1 for c=3:model+1
x(:,c) = x(:,c-1).*x(:,2); x(:,c) = x(:,c-1).*x(:,2);
end end

View File

@ -19,16 +19,16 @@ function disp(A)
%! @end deftypefn %! @end deftypefn
%@eod: %@eod:
separator = repmat(' | ',A.nobs+1,1); separator = repmat(' | ', nobs(A)+1,1);
vspace = ' '; vspace = ' ';
TABLE = ' '; TABLE = ' ';
for t=1:A.nobs for t=1:nobs(A)
TABLE = char(TABLE, date2string(A.dates(t))); TABLE = char(TABLE, date2string(A.dates(t)));
end end
for i = 1:A.vobs for i = 1:vobs(A)
TABLE = horzcat(TABLE,separator); TABLE = horzcat(TABLE,separator);
tmp = A.name{i}; tmp = A.name{i};
for t=1:A.nobs for t=1:nobs(A)
tmp = char(tmp,num2str(A.data(t,i))); tmp = char(tmp,num2str(A.data(t,i)));
end end
TABLE = horzcat(TABLE, tmp); TABLE = horzcat(TABLE, tmp);

View File

@ -21,16 +21,16 @@ function display(A)
vspace = ' '; vspace = ' ';
TABLE = ' '; TABLE = ' ';
if A.vobs<=10 if vobs(A)<=10
if A.nobs<=40 if nobs(A)<=40
separator = repmat(' | ',A.nobs+1,1); separator = repmat(' | ', nobs(A)+1,1);
for t=1:A.nobs for t=1:nobs(A)
TABLE = char(TABLE, date2string(A.dates(t))); TABLE = char(TABLE, date2string(A.dates(t)));
end end
for i = 1:A.vobs for i = 1:vobs(A)
TABLE = horzcat(TABLE,separator); TABLE = horzcat(TABLE,separator);
tmp = A.name{i}; tmp = A.name{i};
for t=1:A.nobs for t=1:nobs(A)
tmp = char(tmp,num2str(A.data(t,i))); tmp = char(tmp,num2str(A.data(t,i)));
end end
TABLE = horzcat(TABLE, tmp); TABLE = horzcat(TABLE, tmp);
@ -42,17 +42,17 @@ if A.vobs<=10
TABLE = char(TABLE, date2string(A.dates(t))); TABLE = char(TABLE, date2string(A.dates(t)));
end end
TABLE = char(TABLE,vspace); 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))); TABLE = char(TABLE, date2string(A.dates(t)));
end end
for i=1:A.vobs for i=1:vobs(A)
TABLE = horzcat(TABLE,separator); TABLE = horzcat(TABLE,separator);
tmp = A.name{i}; tmp = A.name{i};
for t=1:10 for t=1:10
tmp = char(tmp,num2str(A.data(t,i))); tmp = char(tmp,num2str(A.data(t,i)));
end end
tmp = char(tmp,vspace); 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))); tmp = char(tmp,num2str(A.data(t,i)));
end end
TABLE = horzcat(TABLE, tmp); TABLE = horzcat(TABLE, tmp);
@ -60,24 +60,24 @@ if A.vobs<=10
end end
else else
m = 4; m = 4;
if A.nobs<=40 if nobs(A)<=40
separator = repmat(' | ',A.nobs+1,1); separator = repmat(' | ', nobs(A)+1,1);
for t=1:A.nobs for t=1:nobs(A)
TABLE = char(TABLE, date2string(A.dates(t))); TABLE = char(TABLE, date2string(A.dates(t)));
end end
for i = 1:m for i = 1:m
TABLE = horzcat(TABLE,separator); TABLE = horzcat(TABLE,separator);
tmp = A.name{i}; tmp = A.name{i};
for t=1:A.nobs for t=1:nobs(A)
tmp = char(tmp,num2str(A.data(t,i))); tmp = char(tmp,num2str(A.data(t,i)));
end end
TABLE = horzcat(TABLE, tmp); TABLE = horzcat(TABLE, tmp);
end end
TABLE = horzcat(TABLE, separator, repmat(' ... ', A.nobs+1,1)); TABLE = horzcat(TABLE, separator, repmat(' ... ', nobs(A)+1,1));
for i = A.vobs-m+1:A.vobs for i = vobs(A)-m+1:vobs(A)
TABLE = horzcat(TABLE,separator); TABLE = horzcat(TABLE,separator);
tmp = A.name{i}; tmp = A.name{i};
for t=1:A.nobs for t=1:nobs(A)
tmp = char(tmp,num2str(A.data(t,i))); tmp = char(tmp,num2str(A.data(t,i)));
end end
TABLE = horzcat(TABLE, tmp); TABLE = horzcat(TABLE, tmp);
@ -89,7 +89,7 @@ else
TABLE = char(TABLE, date2string(A.dates(t))); TABLE = char(TABLE, date2string(A.dates(t)));
end end
TABLE = char(TABLE,vspace); 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))); TABLE = char(TABLE, date2string(A.dates(t)));
end end
for i=1:m for i=1:m
@ -99,20 +99,20 @@ else
tmp = char(tmp,num2str(A.data(t,i))); tmp = char(tmp,num2str(A.data(t,i)));
end end
tmp = char(tmp,vspace); 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))); tmp = char(tmp,num2str(A.data(t,i)));
end end
TABLE = horzcat(TABLE, tmp); TABLE = horzcat(TABLE, tmp);
end end
TABLE = horzcat(TABLE, separator, repmat(' ... ', 2*n+3,1)); 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); TABLE = horzcat(TABLE,separator);
tmp = A.name{i}; tmp = A.name{i};
for t=1:10 for t=1:10
tmp = char(tmp,num2str(A.data(t,i))); tmp = char(tmp,num2str(A.data(t,i)));
end end
tmp = char(tmp,vspace); 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))); tmp = char(tmp,num2str(A.data(t,i)));
end end
TABLE = horzcat(TABLE, tmp); TABLE = horzcat(TABLE, tmp);

View File

@ -79,8 +79,6 @@ function ts = dseries(varargin) % --*-- Unitary tests --*--
if nargin>0 && ischar(varargin{1}) && isequal(varargin{1},'initialize') if nargin>0 && ischar(varargin{1}) && isequal(varargin{1},'initialize')
ts = struct; ts = struct;
ts.data = []; ts.data = [];
ts.nobs = 0;
ts.vobs = 0;
ts.name = {}; ts.name = {};
ts.tex = {}; ts.tex = {};
ts.dates = dates(); ts.dates = dates();
@ -137,9 +135,7 @@ switch nargin
end end
ts.data = data; ts.data = data;
ts.name = varlist; ts.name = varlist;
ts.vobs = length(varlist); ts.dates = init:init+(nobs(ts)-1);
ts.nobs = size(data,1);
ts.dates = init:init+(ts.nobs-1);
if isempty(tex) if isempty(tex)
ts.tex = name2tex(varlist); ts.tex = name2tex(varlist);
else else
@ -147,10 +143,9 @@ switch nargin
end end
elseif isnumeric(varargin{1}) && isequal(ndims(varargin{1}),2) elseif isnumeric(varargin{1}) && isequal(ndims(varargin{1}),2)
ts.data = varargin{1}; ts.data = varargin{1};
[ts.nobs, ts.vobs] = size(ts.data); ts.name = default_name(vobs(ts));
ts.name = default_name(ts.vobs);
ts.tex = name2tex(ts.name); 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 end
case {2,3,4} case {2,3,4}
if isequal(nargin,2) && ischar(varargin{1}) && isdates(varargin{2}) if isequal(nargin,2) && ischar(varargin{1}) && isdates(varargin{2})
@ -185,29 +180,26 @@ switch nargin
end end
% Get data, number of observations and number of variables. % Get data, number of observations and number of variables.
ts.data = a; ts.data = a;
ts.nobs = size(a,1);
ts.vobs = size(a,2);
% Get the first date and set the frequency. % Get the first date and set the frequency.
if isempty(b) if isempty(b)
init = dates(1,1); init = dates(1,1);
elseif (isdates(b) && isequal(length(b),1)) elseif (isdates(b) && isequal(length(b),1))
init = b; 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); init = dates(b);
elseif (isnumeric(b) && isscalar(b) && isint(b)) % Yearly data. elseif (isnumeric(b) && isscalar(b) && isint(b)) % Yearly data.
init = dates([num2str(b) 'Y']); init = dates([num2str(b) 'Y']);
elseif isdates(b) % Range of dates elseif isdates(b) % Range of dates
init = b(1); 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 = '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, ' the number of rows in the first input, unless the first input');
message = char(message, ' has only one row.'); message = char(message, ' has only one row.');
skipline() skipline()
disp(message); disp(message);
error(' '); error(' ');
elseif isequal(ts.nobs, 1) elseif isequal(nobs(ts), 1)
ts.data = repmat(ts.data,b.ndat,1); ts.data = repmat(ts.data,b.ndat,1);
ts.nobs = b.ndat;
end end
ts.dates = b; ts.dates = b;
elseif (isnumeric(b) && isint(b)) % Range of yearly dates. elseif (isnumeric(b) && isint(b)) % Range of yearly dates.
@ -220,19 +212,19 @@ switch nargin
end end
% Get the names of the variables. % Get the names of the variables.
if ~isempty(c) if ~isempty(c)
if ts.vobs==length(c) if vobs(ts)==length(c)
for i=1:ts.vobs for i=1:vobs(ts)
ts.name = vertcat(ts.name, c(i)); ts.name = vertcat(ts.name, c(i));
end end
else else
error('dseries::dseries: The number of declared names does not match the number of variables!') error('dseries::dseries: The number of declared names does not match the number of variables!')
end end
else else
ts.name = default_name(ts.vobs); ts.name = default_name(vobs(ts));
end end
if ~isempty(d) if ~isempty(d)
if ts.vobs==length(d) if vobs(ts)==length(d)
for i=1:ts.vobs for i=1:vobs(ts)
ts.tex = vertcat(ts.tex, d(i)); ts.tex = vertcat(ts.tex, d(i));
end end
else else
@ -246,7 +238,7 @@ switch nargin
end end
if isempty(ts.dates) if isempty(ts.dates)
ts.dates = init:init+(ts.nobs-1); ts.dates = init:init+(nobs(ts)-1);
end end
%@test:1 %@test:1
@ -349,12 +341,12 @@ end
%@test:6 %@test:6
%$ t = zeros(8,1); %$ t = zeros(8,1);
%$ %$
%$ %try %$ try
%$ ts = dseries(transpose(1:5),[]); %$ ts = dseries(transpose(1:5),[]);
%$ t(1) = 1; %$ t(1) = 1;
%$ %catch %$ catch
%$ % t = 0; %$ t = 0;
%$ %end %$ end
%$ %$
%$ if length(t)>1 %$ if length(t)>1
%$ t(2) = dyn_assert(ts.freq,1); %$ t(2) = dyn_assert(ts.freq,1);

View File

@ -18,4 +18,4 @@ function lastIndex = end(o, k, n)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(k==1 && n==1, 'dseries::end: Wrong indexing!'); assert(k==1 && n==1, 'dseries::end: Wrong indexing!');
lastIndex = o.vobs; lastIndex = vobs(o);

View File

@ -37,13 +37,13 @@ if ~(isdseries(A) && isdseries(B))
error('dseries::eq: Both input arguments must be dseries objects!') error('dseries::eq: Both input arguments must be dseries objects!')
end 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!') warning('dseries::eq: Both input arguments should have the same number of observations!')
C = 0; C = 0;
return return
end 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!') warning('dseries::eq: Both input arguments should have the same number of observations!')
C = 0; C = 0;
return return

View File

@ -46,7 +46,7 @@ function ts = exp(ts)
ts.data = exp(ts.data); ts.data = exp(ts.data);
for i=1:ts.vobs for i=1:vobs(ts)
ts.name(i) = {['exp(' ts.name{i} ')']}; ts.name(i) = {['exp(' ts.name{i} ')']};
ts.tex(i) = {['\exp(' ts.tex{i} ')']}; ts.tex(i) = {['\exp(' ts.tex{i} ')']};
end end

View File

@ -126,8 +126,6 @@ end
A.data = B.data(:,idVariableName); A.data = B.data(:,idVariableName);
A.dates = B.dates; A.dates = B.dates;
A.nobs = B.nobs;
A.vobs = length(idVariableName);
A.name = B.name(idVariableName); A.name = B.name(idVariableName);
A.tex = B.tex(idVariableName); A.tex = B.tex(idVariableName);

View File

@ -68,41 +68,38 @@ function a = concatenate(b,c)
a = dseries(); a = dseries();
end end
d_nobs_flag = 0; d_nobs_flag = 0;
if ~isequal(b.nobs,c.nobs) if ~isequal(nobs(b),nobs(c))
d_nobs_flag = 1; d_nobs_flag = 1;
else
a.nobs = b.nobs;
end end
d_init_flag = 0; d_init_flag = 0;
if ~isequal(firstdate(b),firstdate(c)) if ~isequal(firstdate(b),firstdate(c))
d_init_flag = 1; d_init_flag = 1;
end end
a.vobs = b.vobs+c.vobs;
a.name = vertcat(b.name,c.name); a.name = vertcat(b.name,c.name);
a.tex = vertcat(b.tex,c.tex); a.tex = vertcat(b.tex,c.tex);
if ~( d_nobs_flag(1) || d_init_flag(1) ) if ~( d_nobs_flag(1) || d_init_flag(1) )
a.data = [b.data,c.data]; a.data = [b.data,c.data];
a.dates = b.dates; a.dates = b.dates;
else else
nobs_b = nobs(b);
nobs_c = nobs(c);
if firstdate(b)<=firstdate(c) if firstdate(b)<=firstdate(c)
if firstdate(b)<firstdate(c) if firstdate(b)<firstdate(c)
c.data = [NaN(firstdate(c)-firstdate(b),c.vobs); c.data]; c.data = [NaN(firstdate(c)-firstdate(b), vobs(c)); c.data];
end end
else else
b_first_lines = firstdate(b)-firstdate(c); b.data = [NaN(firstdate(b)-firstdate(c), vobs(b)); b.data];
b.data = [NaN(firstdate(b)-firstdate(c),b.vobs); b.data];
end end
b_last_date = firstdate(b)+b.nobs; b_last_date = firstdate(b)+nobs_b;
c_last_date = firstdate(c)+c.nobs; c_last_date = firstdate(c)+nobs_c;
if b_last_date<c_last_date if b_last_date<c_last_date
b.data = [b.data; NaN(c_last_date-b_last_date,b.vobs)]; b.data = [b.data; NaN(c_last_date-b_last_date, vobs(b))];
elseif b_last_date>c_last_date elseif b_last_date>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 end
a.data = [b.data, c.data]; a.data = [b.data, c.data];
a.dates = unique([b.dates, c.dates]); a.dates = unique([b.dates, c.dates]);
end end
a.nobs = size(a.data,1);
%@test:1 %@test:1
%$ % Define a data set. %$ % Define a data set.

View File

@ -36,7 +36,7 @@ else
lambda = []; lambda = [];
end end
for i=1:ts.vobs for i=1:vobs(ts)
ts.name(i) = {['hpcycle(' ts.name{i} ')']}; ts.name(i) = {['hpcycle(' ts.name{i} ')']};
ts.tex(i) = {['\text{hpcycle}(' ts.tex{i} ')']}; ts.tex(i) = {['\text{hpcycle}(' ts.tex{i} ')']};
end end

View File

@ -36,7 +36,7 @@ else
lambda = []; lambda = [];
end end
for i=1:ts.vobs for i=1:vobs(ts)
ts.name(i) = {['hptrend(' ts.name{i} ')']}; ts.name(i) = {['hptrend(' ts.name{i} ')']};
ts.tex(i) = {['\text{hptrend}(' ts.tex{i} ')']}; ts.tex(i) = {['\text{hptrend}(' ts.tex{i} ')']};
end end

View File

@ -74,11 +74,6 @@ for i=1:n
id = id+1; id = id+1;
end end
% Update vobs member.
ts.vobs = columns(ts.data);
%@test:1 %@test:1
%$ % Define a datasets. %$ % Define a datasets.
%$ A = rand(10,3); B = rand(5,2); %$ A = rand(10,3); B = rand(5,2);

View File

@ -36,5 +36,5 @@ function b = isempty(A)
% %
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
b = isempty(A.data) && isequal(A.nobs,0) && isequal(A.vobs,0); b = isempty(A.data);

View File

@ -34,12 +34,12 @@ if ~isdseries(B)
error('dseries::isequal: Both input arguments must be dseries objects!') error('dseries::isequal: Both input arguments must be dseries objects!')
end end
if ~isequal(A.nobs,B.nobs) if ~isequal(nobs(A), nobs(B))
C = 0; C = 0;
return return
end end
if ~isequal(A.vobs,B.vobs) if ~isequal(vobs(A), vobs(B))
C = 0; C = 0;
return return
end end

View File

@ -52,9 +52,9 @@ end
us = ts; us = ts;
% Update data member % 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.name(i) = {[ 'lag(' ts.name{i} ',' int2str(p) ')']};
us.tex(i) = {[ ts.tex{i} '_{-' int2str(p) '}']}; us.tex(i) = {[ ts.tex{i} '_{-' int2str(p) '}']};
end end

View File

@ -52,9 +52,9 @@ end
us = ts; us = ts;
% Update data member % 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.name(i) = {[ 'lead(' ts.name{i} ',' int2str(p) ')']};
us.tex(i) = {[ ts.tex{i} '_{+' int2str(p) '}']}; us.tex(i) = {[ ts.tex{i} '_{+' int2str(p) '}']};
end end

View File

@ -47,7 +47,7 @@ if any(ts.data<eps)
error('dseries::log: Input argument has to be strictly positive!') error('dseries::log: Input argument has to be strictly positive!')
end end
for i=1:ts.vobs for i=1:vobs(ts)
ts.name(i) = {['log(' ts.name{i} ')']}; ts.name(i) = {['log(' ts.name{i} ')']};
ts.tex(i) = {['\log(' ts.tex{i} ')']}; ts.tex(i) = {['\log(' ts.tex{i} ')']};
end end

View File

@ -51,46 +51,45 @@ end
A = dseries(); A = dseries();
[A.name, IBC, junk] = unique([B.name; C.name], 'last'); [A.name, IBC, junk] = unique([B.name; C.name], 'last');
tex = [B.tex; C.tex]; tex = [B.tex; C.tex];
A.tex = tex(IBC); A.tex = tex(IBC);
A.vobs=length(IBC);
if B.nobs == 0 if nobs(B) == 0
A = C; A = C;
elseif C.nobs == 0 elseif nobs(C) == 0
A = B; A = B;
elseif firstdate(B) >= firstdate(C) elseif firstdate(B) >= firstdate(C)
diff = firstdate(B) - firstdate(C); diff = firstdate(B) - firstdate(C);
A.nobs = max(B.nobs + diff, C.nobs); A_nobs = max(nobs(B) + diff, nobs(C));
A.data = NaN(A.nobs, A.vobs); A.data = NaN(A_nobs, vobs(A));
Z1 = [NaN(diff,B.vobs);B.data]; Z1 = [NaN(diff, vobs(B));B.data];
if A.nobs > B.nobs + diff if nobs(A) > nobs(B) + diff
Z1 = [Z1; NaN(A.nobs-(B.nobs + diff),B.vobs)]; Z1 = [Z1; NaN(nobs(A)-(nobs(B) + diff), vobs(B))];
end; end;
Z2 = C.data; Z2 = C.data;
if A.nobs > C.nobs if nobs(A) > nobs(C)
Z2 = [Z2; NaN(A.nobs - C.nobs,C.vobs)]; Z2 = [Z2; NaN(nobs(A) - nobs(C), vobs(C))];
end; end;
Z = [Z1 Z2]; Z = [Z1 Z2];
A.data = Z(:,IBC); A.data = Z(:,IBC);
A_init = firstdate(C); A_init = firstdate(C);
else else
diff = firstdate(C) - firstdate(B); diff = firstdate(C) - firstdate(B);
A.nobs = max(C.nobs + diff, B.nobs); A_nobs = max(nobs(C) + diff, nobs(B));
A.data = NaN(A.nobs, A.vobs); A.data = NaN(A_nobs, vobs(A));
Z1 = [NaN(diff,C.vobs);C.data]; Z1 = [NaN(diff, vobs(C)); C.data];
if A.nobs > C.nobs + diff if nobs(A) > nobs(C) + diff
Z1 = [Z1; NaN(A.nobs-(C.nobs + diff),C.vobs)]; Z1 = [Z1; NaN(nobs(A)-(nobs(C) + diff), vobs(C))];
end; end
Z2 = B.data; Z2 = B.data;
if A.nobs > B.nobs if nobs(A) > nobs(B)
Z2 = [Z2; NaN(A.nobs - B.nobs,B.vobs)]; Z2 = [Z2; NaN(nobs(A) - nobs(B), vobs(B))];
end; end;
Z = [Z2 Z1]; Z = [Z2 Z1];
A.data = Z(:,IBC); A.data = Z(:,IBC);
A_init = B.init; A_init = B.init;
end end
A.dates = A_init:A_init+(A.nobs-1); A.dates = A_init:A_init+(nobs(A)-1);
%@test:1 %@test:1
%$ % Define a datasets. %$ % Define a datasets.

View File

@ -58,18 +58,18 @@ if isnumeric(C) && (isscalar(C) || isvector(C))
return return
end 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)!']) error(['dseries::minus: Cannot substract ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!'])
else else
if B.vobs>C.vobs if vobs(B)>vobs(C)
idB = 1:B.vobs; idB = 1:vobs(B);
idC = ones(1:B.vobs); idC = ones(1:vobs(B));
elseif B.vobs<C.vobs elseif vobs(B)<vobs(C)
idB = ones(1,C.vobs); idB = ones(1,vobs(C));
idC = 1:C.vobs; idC = 1:vobs(C);
else else
idB = 1:B.vobs; idB = 1:vobs(B);
idC = 1:C.vobs; idC = 1:vobs(C);
end end
end end
@ -77,7 +77,7 @@ if ~isequal(frequency(B),frequency(C))
error(['dseries::plus: Cannot substract ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!']) error(['dseries::plus: Cannot substract ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!'])
end end
if ~isequal(B.nobs,C.nobs) || ~isequal(firstdate(B),firstdate(C)) if ~isequal(nobs(B), nobs(C)) || ~isequal(firstdate(B),firstdate(C))
[B, C] = align(B, C); [B, C] = align(B, C);
end end
@ -94,11 +94,10 @@ end
A = dseries(); A = dseries();
A.dates = B.dates; A.dates = B.dates;
A.nobs = max(B.nobs,C.nobs); A_vobs = max(vobs(B), vobs(C));
A.vobs = max(B.vobs,C.vobs); A.name = cell(A_vobs,1);
A.name = cell(A.vobs,1); A.tex = cell(A_vobs,1);
A.tex = cell(A.vobs,1); for i=1:A_vobs
for i=1:A.vobs
A.name(i) = {['minus(' B.name{idB(i)} ',' C.name{idC(i)} ')']}; A.name(i) = {['minus(' B.name{idB(i)} ',' C.name{idC(i)} ')']};
A.tex(i) = {['(' B.tex{idB(i)} '-' C.tex{idC(i)} ')']}; A.tex(i) = {['(' B.tex{idB(i)} '-' C.tex{idC(i)} ')']};
end end

View File

@ -61,31 +61,27 @@ end
if isdseries(B) && isnumeric(C) && isreal(C) && isscalar(C) if isdseries(B) && isnumeric(C) && isreal(C) && isscalar(C)
A = dseries(); A = dseries();
A.dates = B.dates; A.dates = B.dates;
A.nobs = B.nobs; A.data = B.data.^C;
A.vobs = B.vobs; A.name = cell(vobs(A),1);
A.name = cell(A.vobs,1); A.tex = cell(vobs(A),1);
A.tex = cell(A.vobs,1); for i=1:vobs(A)
for i=1:A.vobs
A.name(i) = {['power(' B.name{i} ',' num2str(C) ')']}; A.name(i) = {['power(' B.name{i} ',' num2str(C) ')']};
A.tex(i) = {[B.tex{i} '^' num2str(C) ]}; A.tex(i) = {[B.tex{i} '^' num2str(C) ]};
end end
A.data = B.data.^C;
return return
end end
if isdseries(B) && isdseries(C) if isdseries(B) && isdseries(C)
if isequal(B.nobs,C.nobs) && isequal(B.vobs,C.vobs) && isequal(frequency(B),frequency(C)) if isequal(nobs(B),nobs(C)) && isequal(vobs(B), vobs(C)) && isequal(frequency(B),frequency(C))
A = dseries(); A = dseries();
A.data = B.data.^C.data;
A.dates = B.dates; A.dates = B.dates;
A.nobs = B.nobs; A.name = cell(vobs(A),1);
A.vobs = B.vobs; A.tex = cell(vobs(A),1);
A.name = cell(A.vobs,1); for i=1:vobs(A)
A.tex = cell(A.vobs,1);
for i=1:A.vobs
A.name(i) = {['power(' B.name{i} ',' C.name{i} ')']}; A.name(i) = {['power(' B.name{i} ',' C.name{i} ')']};
A.tex(i) = {[B.tex{i} '^{' C.tex{i} '}']}; A.tex(i) = {[B.tex{i} '^{' C.tex{i} '}']};
end end
A.data = B.data.^C.data;
else else
error('dseries::mpower: If both input arguments are dseries objects, they must have the same numbers of variables and observations and common frequency!') error('dseries::mpower: If both input arguments are dseries objects, they must have the same numbers of variables and observations and common frequency!')
end end

View File

@ -60,33 +60,32 @@ end
if isdseries(B) && isdseries(C) if isdseries(B) && isdseries(C)
% Element by element divisions of two dseries object % Element by element divisions of two dseries object
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::times: Cannot divide ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!']) error(['dseries::times: Cannot divide ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!'])
else else
if B.vobs>C.vobs if vobs(B)>vobs(C)
idB = 1:B.vobs; idB = 1:vobs(B);
idC = ones(1:B.vobs); idC = ones(1:vobs(B));
elseif B.vobs<C.vobs elseif vobs(B)<vobs(C)
idB = ones(1,C.vobs); idB = ones(1,vobs(C));
idC = 1:C.vobs; idC = 1:vobs(C);
else else
idB = 1:B.vobs; idB = 1:vobs(B);
idC = 1:C.vobs; idC = 1:vobs(C);
end end
end end
if ~isequal(frequency(B),frequency(C)) if ~isequal(frequency(B),frequency(C))
error(['dseries::times: Cannot divide ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!']) error(['dseries::times: Cannot divide ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!'])
end end
if ~isequal(B.nobs,C.nobs) || ~isequal(firstdate(B),firstdate(C)) if ~isequal(nobs(B), nobs(C)) || ~isequal(firstdate(B),firstdate(C))
[B, C] = align(B, C); [B, C] = align(B, C);
end end
A = dseries(); A = dseries();
A.dates = B.dates; A.dates = B.dates;
A.nobs = max(B.nobs,C.nobs); A_vobs = max(vobs(B),vobs(C));
A.vobs = max(B.vobs,C.vobs); A.name = cell(A_vobs,1);
A.name = cell(A.vobs,1); A.tex = cell(A_vobs,1);
A.tex = cell(A.vobs,1); for i=1:A_vobs
for i=1:A.vobs
A.name(i) = {['divide(' B.name{idB(i)} ',' C.name{idC(i)} ')']}; A.name(i) = {['divide(' B.name{idB(i)} ',' C.name{idC(i)} ')']};
A.tex(i) = {['(' B.tex{idB(i)} '/' C.tex{idC(i)} ')']}; A.tex(i) = {['(' B.tex{idB(i)} '/' C.tex{idC(i)} ')']};
end end

View File

@ -60,33 +60,32 @@ end
if isdseries(B) && isdseries(C) if isdseries(B) && isdseries(C)
% Element by element multiplication of two dseries object % Element by element multiplication of two dseries object
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::times: Cannot multiply ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!']) error(['dseries::times: Cannot multiply ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!'])
else else
if B.vobs>C.vobs if vobs(B)>vobs(C)
idB = 1:B.vobs; idB = 1:vobs(B);
idC = ones(1:B.vobs); idC = ones(1:vobs(B));
elseif B.vobs<C.vobs elseif vobs(B)<vobs(C)
idB = ones(1,C.vobs); idB = ones(1,vobs(C));
idC = 1:C.vobs; idC = 1:vobs(C);
else else
idB = 1:B.vobs; idB = 1:vobs(B);
idC = 1:C.vobs; idC = 1:vobs(C);
end end
end end
if ~isequal(frequency(B),frequency(C)) if ~isequal(frequency(B),frequency(C))
error(['dseries::times: Cannot multiply ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!']) error(['dseries::times: Cannot multiply ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!'])
end end
if ~isequal(B.nobs,C.nobs) || ~isequal(firstdate(B),firstdate(C)) if ~isequal(nobs(B), nobs(C)) || ~isequal(firstdate(B),firstdate(C))
[B, C] = align(B, C); [B, C] = align(B, C);
end end
A = dseries(); A = dseries();
A.dates = B.dates; A.dates = B.dates;
A.nobs = max(B.nobs,C.nobs); A_vobs = max(vobs(B),vobs(C));
A.vobs = max(B.vobs,C.vobs); A.name = cell(A_vobs,1);
A.name = cell(A.vobs,1); A.tex = cell(A_vobs,1);
A.tex = cell(A.vobs,1); for i=1:A_vobs
for i=1:A.vobs
A.name(i) = {['multiply(' B.name{idB(i)} ',' C.name{idC(i)} ')']}; A.name(i) = {['multiply(' B.name{idB(i)} ',' C.name{idC(i)} ')']};
A.tex(i) = {['(' B.tex{idB(i)} '*' C.tex{idC(i)} ')']}; A.tex(i) = {['(' B.tex{idB(i)} '*' C.tex{idC(i)} ')']};
end end

View File

@ -37,13 +37,13 @@ if ~(isdseries(A) && isdseries(B))
error('dseries::ne: Both input arguments must be dseries objects!') error('dseries::ne: Both input arguments must be dseries objects!')
end end
if ~isequal(A.nobs,B.nobs) if ~isequal(nobs(A), nobs(B))
warning('dseries::ne: Both input arguments should have the same number of observations!') warning('dseries::ne: Both input arguments should have the same number of observations!')
C = 1; C = 1;
return return
end end
if ~isequal(A.vobs,B.vobs) if ~isequal(vobs(A), vobs(B))
warning('dseries::ne: Both input arguments should have the same number of observations!') warning('dseries::ne: Both input arguments should have the same number of observations!')
C = 1; C = 1;
return return

22
matlab/@dseries/nobs.m Normal file
View File

@ -0,0 +1,22 @@
function s = nobs(ts)
% Returns the number of observations 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 <http://www.gnu.org/licenses/>.
s = rows(ts.data);

View File

@ -22,26 +22,26 @@ function h = plot(ts, varargin)
% Get the number of dseries objects % Get the number of dseries objects
if isequal(nargin,1) if isequal(nargin,1)
ndseries = 1; ndseries = 1;
nvariables = ts.vobs; nvariables = vobs(ts);
nobservations = ts.nobs; nobservations = nobs(ts);
else else
if isdseries(varargin{1}) if isdseries(varargin{1})
ndseries = 2; ndseries = 2;
nvariables = ts.vobs; nvariables = vobs(ts);
nobservations = ts.nobs; nobservations = nobs(ts);
if nargin>2 && any(cellfun(@isdseries,varargin(2:end))) if nargin>2 && any(cellfun(@isdseries,varargin(2:end)))
error('dseries::plot: You cannot pass more two dseries objects!') error('dseries::plot: You cannot pass more two dseries objects!')
end 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!') error('dseries::plot: The two dseries objects must have the same number of variables!')
end 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!') error('dseries::plot: The two dseries objects must have the same number of observations!')
end end
else else
ndseries = 1; ndseries = 1;
nvariables = ts.vobs; nvariables = vobs(ts);
nobservations = ts.nobs; nobservations = nobs(ts);
end end
end end

View File

@ -58,18 +58,18 @@ if isnumeric(C) && (isscalar(C) || isvector(C))
return return
end 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)!']) error(['dseries::plus: Cannot add ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!'])
else else
if B.vobs>C.vobs if vobs(B)>vobs(C)
idB = 1:B.vobs; idB = 1:vobs(B);
idC = ones(1,B.vobs); idC = ones(1,vobs(B));
elseif B.vobs<C.vobs elseif vobs(B)<vobs(C)
idB = ones(1,C.vobs); idB = ones(1,vobs(C));
idC = 1:C.vobs; idC = 1:vobs(C);
else else
idB = 1:B.vobs; idB = 1:vobs(B);
idC = 1:C.vobs; idC = 1:vobs(C);
end end
end end
@ -77,7 +77,7 @@ if ~isequal(frequency(B),frequency(C))
error(['dseries::plus: Cannot add ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!']) error(['dseries::plus: Cannot add ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!'])
end end
if ~isequal(B.nobs,C.nobs) || ~isequal(firstdate(B),firstdate(C)) if ~isequal(nobs(B), nobs(C)) || ~isequal(firstdate(B),firstdate(C))
[B, C] = align(B, C); [B, C] = align(B, C);
end end
@ -93,19 +93,16 @@ end
A = dseries(); A = dseries();
A.data = bsxfun(@plus,B.data,C.data);
A.dates = B.dates; A.dates = B.dates;
%A.freq = B.freq;
%A.init = B.init; A_vobs = max(vobs(B), vobs(C));
A.nobs = max(B.nobs,C.nobs); A.name = cell(A_vobs,1);
A.vobs = max(B.vobs,C.vobs); A.tex = cell(A_vobs,1);
A.name = cell(A.vobs,1); for i=1:A_vobs
A.tex = cell(A.vobs,1);
for i=1:A.vobs
A.name(i) = {['plus(' B.name{idB(i)} ',' C.name{idC(i)} ')']}; A.name(i) = {['plus(' B.name{idB(i)} ',' C.name{idC(i)} ')']};
A.tex(i) = {['(' B.tex{idB(i)} '+' C.tex{idC(i)} ')']}; A.tex(i) = {['(' B.tex{idB(i)} '+' C.tex{idC(i)} ')']};
end end
A.data = bsxfun(@plus,B.data,C.data);
%A.dates = A.init:A.init+(A.nobs-1);
%@test:1 %@test:1
%$ % Define a datasets. %$ % Define a datasets.

View File

@ -47,7 +47,7 @@ function [ts,id] = pop(ts,a) % --*-- Unitary tests --*--
if nargin<2 if nargin<2
% Removes the last variable % Removes the last variable
id = ts.vobs; id = vobs(ts);
else else
id = find(strcmp(a,ts.name)); id = find(strcmp(a,ts.name));
end end
@ -57,7 +57,6 @@ if isempty(id)
return return
end end
ts.vobs = ts.vobs-1;
ts.data(:,id) = []; ts.data(:,id) = [];
ts.name(id) = []; ts.name(id) = [];
ts.tex(id) = []; ts.tex(id) = [];

View File

@ -47,14 +47,14 @@ switch frequency(ts)
case 4 case 4
us.data(2:end,:) = ts.data(2:end,:)-ts.data(1:end-1,:); us.data(2:end,:) = ts.data(2:end,:)-ts.data(1:end-1,:);
us.data(1,:) = NaN; us.data(1,:) = NaN;
for i = 1:ts.vobs for i = 1:vobs(ts)
us.name(i) = {['qdiff(' us.name{i} ')']}; us.name(i) = {['qdiff(' us.name{i} ')']};
us.tex(i) = {['\Delta ' us.tex{i}]}; us.tex(i) = {['\Delta ' us.tex{i}]};
end end
case 12 case 12
us.data(4:end,:) = ts.data(4:end,:)-ts.data(1:end-3,:); us.data(4:end,:) = ts.data(4:end,:)-ts.data(1:end-3,:);
us.data(1:3,:) = NaN; us.data(1:3,:) = NaN;
for i = 1:ts.vobs for i = 1:vobs(ts)
us.name(i) = {['qdiff(' us.name{i} ')']}; us.name(i) = {['qdiff(' us.name{i} ')']};
us.tex(i) = {['\Delta_3 ' us.tex{i}]}; us.tex(i) = {['\Delta_3 ' us.tex{i}]};
end end

View File

@ -47,14 +47,14 @@ switch frequency(ts)
case 4 case 4
us.data(2:end,:) = ts.data(2:end,:)./ts.data(1:end-1,:) - 1; us.data(2:end,:) = ts.data(2:end,:)./ts.data(1:end-1,:) - 1;
us.data(1,:) = NaN; us.data(1,:) = NaN;
for i = 1:ts.vobs for i = 1:vobs(ts)
us.name(i) = {['qgrowth(' us.name{i} ')']}; us.name(i) = {['qgrowth(' us.name{i} ')']};
us.tex(i) = {['\delta ' us.tex{i}]}; us.tex(i) = {['\delta ' us.tex{i}]};
end end
case 12 case 12
us.data(4:end,:) = ts.data(4:end,:)./ts.data(1:end-3,:) - 1; us.data(4:end,:) = ts.data(4:end,:)./ts.data(1:end-3,:) - 1;
us.data(1:3,:) = NaN; us.data(1:3,:) = NaN;
for i = 1:ts.vobs for i = 1:vobs(ts)
us.name(i) = {['qgrowth(' us.name{i} ')']}; us.name(i) = {['qgrowth(' us.name{i} ')']};
us.tex(i) = {['\delta_3 ' us.tex{i}]}; us.tex(i) = {['\delta_3 ' us.tex{i}]};
end end

View File

@ -39,15 +39,15 @@ switch format
fprintf(fid,'INIT__ = ''%s'';\n',date2string(firstdate(A))); fprintf(fid,'INIT__ = ''%s'';\n',date2string(firstdate(A)));
fprintf(fid,'\n'); fprintf(fid,'\n');
fprintf(fid,'NAMES__ = {'); fprintf(fid,'NAMES__ = {');
for i=1:A.vobs for i=1:vobs(A)
fprintf(fid,[ '''' A.name{i} '''']); fprintf(fid,[ '''' A.name{i} '''']);
if i<A.vobs if i<vobs(A)
fprintf(fid,'; '); fprintf(fid,'; ');
end end
end end
fprintf(fid,'};\n'); fprintf(fid,'};\n');
str = 'TEX__ = {'; str = 'TEX__ = {';
for i=1:A.vobs-1 for i=1:vobs(A)-1
str = [str, '''%s''; ']; str = [str, '''%s''; '];
end end
str = [str, '''%s''};']; str = [str, '''%s''};'];
@ -56,7 +56,7 @@ switch format
str = regexprep(str, pattern, '$1\\\\_'); str = regexprep(str, pattern, '$1\\\\_');
fprintf(fid,str); fprintf(fid,str);
fprintf(fid,'\n\n'); fprintf(fid,'\n\n');
for v=1:A.vobs for v=1:vobs(A)
fprintf(fid,'%s = [\n', A.name{v}); fprintf(fid,'%s = [\n', A.name{v});
fprintf(fid,'%15.8g\n',A.data(1:end-1,v)); fprintf(fid,'%15.8g\n',A.data(1:end-1,v));
fprintf(fid,'%15.8g];\n\n',A.data(end,v)); fprintf(fid,'%15.8g];\n\n',A.data(end,v));
@ -68,7 +68,7 @@ switch format
NAMES__ = A.name; NAMES__ = A.name;
TEX__ = A.tex; TEX__ = A.tex;
str = []; str = [];
for v=1:A.vobs for v=1:vobs(A)
str = [str, A.name{v} ' = A.data(:,' num2str(v) ');' ]; str = [str, A.name{v} ' = A.data(:,' num2str(v) ');' ];
end end
eval(str); eval(str);
@ -83,7 +83,7 @@ switch format
fid = fopen([basename, '.csv'],'w'); fid = fopen([basename, '.csv'],'w');
fprintf(fid,',%s', A.name{:}); fprintf(fid,',%s', A.name{:});
fprintf(fid,'\n'); fprintf(fid,'\n');
for t=1:A.nobs for t=1:nobs(A)
str = sprintf(', %15.8g',A.data(t,:)); str = sprintf(', %15.8g',A.data(t,:));
fprintf(fid, '%s%s\n',date2string(A.dates(t)),str); fprintf(fid, '%s%s\n',date2string(A.dates(t)),str);
end end

View File

@ -48,13 +48,13 @@ if ~isdseries(B)
error(['dseries::rename: ' inputname(1) ' must be a dseries object!']) error(['dseries::rename: ' inputname(1) ' must be a dseries object!'])
end end
if ~isequal(B.vobs,n) if ~isequal(vobs(B),n)
error(['dseries::rename: The number of variables in ' inputname(1) ' does not match the number of declared names!']) error(['dseries::rename: The number of variables in ' inputname(1) ' does not match the number of declared names!'])
end end
A = B; A = B;
for i=1:A.vobs for i=1:vobs(A)
if ~isempty(varargin{i}) if ~isempty(varargin{i})
A.name(i) = { varargin{i} }; A.name(i) = { varargin{i} };
end end

View File

@ -83,11 +83,11 @@ switch length(S)
end end
return return
end end
if ~isequal(length(S(1).subs),B.vobs) if ~isequal(length(S(1).subs),vobs(B))
error('dseries::subsasgn: Wrong syntax!') error('dseries::subsasgn: Wrong syntax!')
end end
if ~isequal(S(1).subs(:),B.name) if ~isequal(S(1).subs(:),B.name)
for i = 1:B.vobs for i = 1:vobs(B)
if ~isequal(S(1).subs{i},B.name{i}) if ~isequal(S(1).subs{i},B.name{i})
% Rename a variable. % Rename a variable.
id = find(strcmp(S(1).subs{i},A.name)); id = find(strcmp(S(1).subs{i},A.name));
@ -106,13 +106,13 @@ switch length(S)
case '.' case '.'
if isequal(S(1).subs,'init') && isdates(B) && isequal(length(B),1) if isequal(S(1).subs,'init') && isdates(B) && isequal(length(B),1)
% Change the initial date (update dates member) % Change the initial date (update dates member)
A.dates = B:B+(A.nobs-1); A.dates = B:B+(nobs(A)-1);
return return
elseif isequal(S(1).subs,'dates') && isdates(B) elseif isequal(S(1).subs,'dates') && isdates(B)
% Overwrite the dates member % Overwrite the dates member
A.dates = B; A.dates = B;
return return
elseif ismember(S(1).subs,{'nobs','vobs','data','name','tex'}) elseif ismember(S(1).subs,{'data','name','tex'})
error(['dseries::subsasgn: You cannot overwrite ' S(1).subs ' member!']) error(['dseries::subsasgn: You cannot overwrite ' S(1).subs ' member!'])
elseif ~isequal(S(1).subs,B.name) elseif ~isequal(S(1).subs,B.name)
% Single variable selection. % Single variable selection.
@ -143,7 +143,7 @@ switch length(S)
if isempty(tdy) if isempty(tdy)
error('dseries::subsasgn: Periods of the dseries objects on the left and right hand sides must intersect!') error('dseries::subsasgn: Periods of the dseries objects on the left and right hand sides must intersect!')
end end
if ~isequal(A.vobs,B.vobs) if ~isequal(vobs(A), vobs(B))
error('dseries::subsasgn: Dimension error! The number of variables on the left and right hand side must match.') error('dseries::subsasgn: Dimension error! The number of variables on the left and right hand side must match.')
end end
A.data(tdx,:) = B.data(tdy,:); A.data(tdx,:) = B.data(tdy,:);
@ -166,28 +166,20 @@ switch length(S)
if isnumeric(B) if isnumeric(B)
if isequal(rows(B),1) if isequal(rows(B),1)
A.data = repmat(B,A.dates.ndat,1); A.data = repmat(B,A.dates.ndat,1);
A.nobs = rows(A.data);
A.vobs = columns(A.data);
elseif isequal(rows(B),A.dates.ndat) elseif isequal(rows(B),A.dates.ndat)
A.data = B; A.data = B;
A.nobs = rows(A.data);
A.vobs = columns(A.data);
else else
error('dseries::subsasgn: Wrong syntax!') error('dseries::subsasgn: Wrong syntax!')
end end
if isempty(A.name) if isempty(A.name)
A.name = default_name(A.vobs); A.name = default_name(vobs(A));
A.tex = name2tex(A.name); A.tex = name2tex(A.name);
end end
elseif isdseries(B) elseif isdseries(B)
if isequal(B.nobs,1) if isequal(nobs(B), 1)
A.data = repmat(B.data,A.dates.ndat,1); A.data = repmat(B.data,A.dates.ndat,1);
A.nobs = rows(A.data); elseif isequal(nobs(B), A.dates.ndat)
A.vobs = columns(A.data);
elseif isequal(B.nobs,A.dates.ndat)
A.data = B; A.data = B;
A.nobs = rows(A.data);
A.vobs = columns(A.data);
else else
error('dseries::subsasgn: Wrong syntax!') error('dseries::subsasgn: Wrong syntax!')
end end
@ -211,7 +203,7 @@ switch length(S)
else else
sA = extract(A,S(1).subs); sA = extract(A,S(1).subs);
end end
if (isdseries(B) && isequal(sA.vobs,B.vobs)) || (isnumeric(B) && isequal(sA.vobs,columns(B))) || (isnumeric(B) && isequal(columns(B),1)) if (isdseries(B) && isequal(vobs(sA), vobs(B))) || (isnumeric(B) && isequal(vobs(sA),columns(B))) || (isnumeric(B) && isequal(columns(B),1))
if isdates(S(2).subs{1}) if isdates(S(2).subs{1})
[junk, tdx] = intersect(sA.dates.time,S(2).subs{1}.time,'rows'); [junk, tdx] = intersect(sA.dates.time,S(2).subs{1}.time,'rows');
if isdseries(B) if isdseries(B)

View File

@ -65,7 +65,7 @@ function B = subsref(A, S) % --*-- Unitary tests --*--
switch S(1).type switch S(1).type
case '.' case '.'
switch S(1).subs switch S(1).subs
case {'data','nobs','vobs','name','tex','dates'} % Public members. case {'data','name','tex','dates'} % Public members.
if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs) if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs)
error(['dseries::subsref: ' S(1).subs ' is not a method but a member!']) error(['dseries::subsref: ' S(1).subs ' is not a method but a member!'])
end end
@ -75,6 +75,12 @@ switch S(1).type
if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs) if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs)
S = shiftS(S,1); S = shiftS(S,1);
end 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' case 'init'
% Returns a dates object (first date). % Returns a dates object (first date).
B = A.dates(1); B = A.dates(1);
@ -177,8 +183,6 @@ switch S(1).type
B.name = A.name(ndx); B.name = A.name(ndx);
B.tex = A.tex(ndx); B.tex = A.tex(ndx);
B.tex = deblank(A.tex(ndx,:)); B.tex = deblank(A.tex(ndx,:));
B.nobs = A.nobs;
B.vobs = 1;
B.dates = A.dates; B.dates = A.dates;
else else
error('dseries::subsref: Unknown public method, public member or variable!') error('dseries::subsref: Unknown public method, public member or variable!')
@ -232,8 +236,6 @@ switch S(1).type
B.data = A.data(tdx,:); B.data = A.data(tdx,:);
B.name = A.name; B.name = A.name;
B.tex = A.tex; B.tex = A.tex;
B.nobs = length(tdx);
B.vobs = A.vobs;
B.dates = A.dates(tdx); B.dates = A.dates(tdx);
elseif isvector(S(1).subs{1}) && all(isint(S(1).subs{1})) 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!'); 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{:}); B = extract(A,S(1).subs{:});
elseif isequal(length(S(1).subs),1) && all(isint(S(1).subs{1})) elseif isequal(length(S(1).subs),1) && all(isint(S(1).subs{1}))
idx = 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!') error('dseries::subsref: Indices are out of bounds!')
end end
B = dseries(); B = dseries();
B.data = A.data(:,idx); B.data = A.data(:,idx);
B.name = A.name(idx); B.name = A.name(idx);
B.tex = A.tex(idx); B.tex = A.tex(idx);
B.nobs = A.nobs;
B.vobs = length(idx);
B.dates = A.dates; B.dates = A.dates;
else else
error('dseries::subsref: What the Hell are you tryin'' to do?!') error('dseries::subsref: What the Hell are you tryin'' to do?!')

View File

@ -21,7 +21,7 @@ assert(nargin <= 3, 'dseries::tex_rename: accepts at most three args');
if nargin == 2 if nargin == 2
newtexname = varargin{1}; 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 else
newtexname = varargin{2}; newtexname = varargin{2};
name = varargin{1}; name = varargin{1};

View File

@ -42,16 +42,15 @@ function A = uminus(B) % --*-- Unitary tests --*--
A = dseries(); A = dseries();
A.nobs = B.nobs; A.data = -(B.data);
A.vobs = B.vobs;
A.dates = B.dates; A.dates = B.dates;
A.name = cell(A.vobs,1);
A.tex = cell(A.vobs,1); A.name = cell(vobs(A),1);
for i = 1:A.vobs A.tex = cell(vobs(A),1);
for i = 1:vobs(A)
A.name(i) = {[ '-' B.name{i}]}; A.name(i) = {[ '-' B.name{i}]};
A.tex(i) = {[ '-' B.tex{i}]}; A.tex(i) = {[ '-' B.tex{i}]};
end end
A.data = -(B.data);
%@test:1 %@test:1
%$ % Define a datasets. %$ % Define a datasets.

View File

@ -63,7 +63,7 @@ function d = vertcat_(b, c)
if ~isequal(frequency(b), frequency(c)) if ~isequal(frequency(b), frequency(c))
error('dseries::vertcat: Frequencies must be common!') error('dseries::vertcat: Frequencies must be common!')
end end
if ~isequal(b.vobs, c.vobs) if ~isequal(vobs(b), vobs(c))
error('dseries::vertcat: Number of variables must be common!') error('dseries::vertcat: Number of variables must be common!')
end end
if ~isequal(b.name, c.name) if ~isequal(b.name, c.name)
@ -72,7 +72,6 @@ function d = vertcat_(b, c)
d = b; d = b;
d.data = [b.data; c.data]; d.data = [b.data; c.data];
d.dates = [b.dates; c.dates]; d.dates = [b.dates; c.dates];
d.nobs = b.nobs+c.nobs;
%@test:1 %@test:1
%$ % Define a data set. %$ % Define a data set.

22
matlab/@dseries/vobs.m Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
s = columns(ts.data);

View File

@ -45,28 +45,28 @@ switch frequency(ts)
case 1 case 1
us.data(2:end,:) = ts.data(2:end,:)-ts.data(1:end-1,:); us.data(2:end,:) = ts.data(2:end,:)-ts.data(1:end-1,:);
us.data(1,:) = NaN; us.data(1,:) = NaN;
for i = 1:ts.vobs for i = 1:vobs(ts)
us.name(i) = {['ydiff(' us.name{i} ')']}; us.name(i) = {['ydiff(' us.name{i} ')']};
us.tex(i) = {['\Delta ' us.tex{i}]}; us.tex(i) = {['\Delta ' us.tex{i}]};
end end
case 4 case 4
us.data(5:end,:) = ts.data(5:end,:)-ts.data(1:end-4,:); us.data(5:end,:) = ts.data(5:end,:)-ts.data(1:end-4,:);
us.data(1:4,:) = NaN; us.data(1:4,:) = NaN;
for i = 1:ts.vobs for i = 1:vobs(ts)
us.name(i) = {['ydiff(' us.name{i} ')']}; us.name(i) = {['ydiff(' us.name{i} ')']};
us.tex(i) = {['\Delta_4 ' us.tex{i}]}; us.tex(i) = {['\Delta_4 ' us.tex{i}]};
end end
case 12 case 12
us.data(13:end,:) = ts.data(13:end,:)-ts.data(1:end-12,:); us.data(13:end,:) = ts.data(13:end,:)-ts.data(1:end-12,:);
us.data(1:12,:) = NaN; us.data(1:12,:) = NaN;
for i = 1:ts.vobs for i = 1:vobs(ts)
us.name(i) = {['ydiff(' us.name{i} ')']}; us.name(i) = {['ydiff(' us.name{i} ')']};
us.tex(i) = {['\Delta_{12} ' us.tex{i}]}; us.tex(i) = {['\Delta_{12} ' us.tex{i}]};
end end
case 52 case 52
us.data(53:end,:) = ts.data(53:end,:)-ts.data(1:end-52,:); us.data(53:end,:) = ts.data(53:end,:)-ts.data(1:end-52,:);
us.data(1:52,:) = NaN; us.data(1:52,:) = NaN;
for i = 1:ts.vobs for i = 1:vobs(ts)
us.name(i) = {['ydiff(' us.name{i} ')']}; us.name(i) = {['ydiff(' us.name{i} ')']};
us.tex(i) = {['\Delta_{52} ' us.tex{i}]}; us.tex(i) = {['\Delta_{52} ' us.tex{i}]};
end end

View File

@ -45,28 +45,28 @@ switch frequency(ts)
case 1 case 1
us.data(2:end,:) = ts.data(2:end,:)./ts.data(1:end-1,:) - 1; us.data(2:end,:) = ts.data(2:end,:)./ts.data(1:end-1,:) - 1;
us.data(1,:) = NaN; us.data(1,:) = NaN;
for i = 1:ts.vobs for i = 1:vobs(ts)
us.name(i) = {['ygrowth(' us.name{i} ')']}; us.name(i) = {['ygrowth(' us.name{i} ')']};
us.tex(i) = {['\delta ' us.tex{i}]}; us.tex(i) = {['\delta ' us.tex{i}]};
end end
case 4 case 4
us.data(5:end,:) = ts.data(5:end,:)./ts.data(1:end-4,:) - 1; us.data(5:end,:) = ts.data(5:end,:)./ts.data(1:end-4,:) - 1;
us.data(1:4,:) = NaN; us.data(1:4,:) = NaN;
for i = 1:ts.vobs for i = 1:vobs(ts)
us.name(i) = {['ygrowth(' us.name{i} ')']}; us.name(i) = {['ygrowth(' us.name{i} ')']};
us.tex(i) = {['\delta_4 ' us.tex{i}]}; us.tex(i) = {['\delta_4 ' us.tex{i}]};
end end
case 12 case 12
us.data(13:end,:) = ts.data(13:end,:)./ts.data(1:end-12,:) - 1; us.data(13:end,:) = ts.data(13:end,:)./ts.data(1:end-12,:) - 1;
us.data(1:12,:) = NaN; us.data(1:12,:) = NaN;
for i = 1:ts.vobs for i = 1:vobs(ts)
us.name(i) = {['ygrowth(' us.name{i} ')']}; us.name(i) = {['ygrowth(' us.name{i} ')']};
us.tex(i) = {['\delta_{12} ' us.tex{i}]}; us.tex(i) = {['\delta_{12} ' us.tex{i}]};
end end
case 52 case 52
us.data(53:end,:) = ts.data(53:end,:)./ts.data(1:end-52,:) - 1; us.data(53:end,:) = ts.data(53:end,:)./ts.data(1:end-52,:) - 1;
us.data(1:52,:) = NaN; us.data(1:52,:) = NaN;
for i = 1:ts.vobs for i = 1:vobs(ts)
us.name(i) = {['ygrowth(' us.name{i} ')']}; us.name(i) = {['ygrowth(' us.name{i} ')']};
us.tex(i) = {['\delta_{52} ' us.tex{i}]}; us.tex(i) = {['\delta_{52} ' us.tex{i}]};
end end