Skip to content
Snippets Groups Projects
Verified Commit c604cefb authored by Houtan Bastani's avatar Houtan Bastani
Browse files

remove unnecessary assignments from dseries constructor

parent 3681da09
No related branches found
No related tags found
No related merge requests found
Pipeline #1787 passed with warnings
...@@ -50,12 +50,6 @@ methods ...@@ -50,12 +50,6 @@ methods
switch nargin switch nargin
case 0 case 0
% Return empty object. % Return empty object.
o.data = [];
o.name = {};
o.tex = {};
o.dates = dates();
o.ops = {};
o.tags = struct();
return return
case 1 case 1
if isdates(varargin{1}) if isdates(varargin{1})
...@@ -64,24 +58,14 @@ methods ...@@ -64,24 +58,14 @@ methods
error('dseries:WrongInputArguments', 'Input (identified as a dates object) must be non empty!'); error('dseries:WrongInputArguments', 'Input (identified as a dates object) must be non empty!');
case 1 case 1
% Create an empty dseries object with an initial date. % Create an empty dseries object with an initial date.
o.data = [];
o.name = {};
o.tex = {};
o.dates = varargin{1}; o.dates = varargin{1};
o.ops = {};
o.tags = struct();
otherwise otherwise
error('dseries:WrongInputArguments', 'Input (identified as a dates object) must have a unique element!'); error('dseries:WrongInputArguments', 'Input (identified as a dates object) must have a unique element!');
end end
return return
elseif ischar(varargin{1}) elseif ischar(varargin{1})
[init, data, varlist, tex, ops, tags] = load_data(varargin{1}); [init, o.data, o.name, o.tex, o.ops, o.tags] = load_data(varargin{1});
o.data = data;
o.name = varlist;
o.dates = init:init+(nobs(o)-1); o.dates = init:init+(nobs(o)-1);
o.tex = tex;
o.ops = ops;
o.tags = tags;
elseif ~isoctave() && ~matlab_ver_less_than('8.2') && istable(varargin{1}) elseif ~isoctave() && ~matlab_ver_less_than('8.2') && istable(varargin{1})
% It is assumed that the dates are in the first column. % It is assumed that the dates are in the first column.
o.name = varargin{1}.Properties.VariableNames(2:end); o.name = varargin{1}.Properties.VariableNames(2:end);
...@@ -89,14 +73,12 @@ methods ...@@ -89,14 +73,12 @@ methods
o.data = varargin{1}{:,2:end}; o.data = varargin{1}{:,2:end};
o.dates = dates(varargin{1}{1,1}{1})+(0:size(varargin{1}, 1)-1); o.dates = dates(varargin{1}{1,1}{1})+(0:size(varargin{1}, 1)-1);
o.ops = cell(length(o.name), 1); o.ops = cell(length(o.name), 1);
o.tags = struct();
elseif isnumeric(varargin{1}) && isequal(ndims(varargin{1}),2) elseif isnumeric(varargin{1}) && isequal(ndims(varargin{1}),2)
o.data = varargin{1}; o.data = varargin{1};
o.name = default_name(vobs(o)); o.name = default_name(vobs(o));
o.tex = name2tex(o.name); o.tex = name2tex(o.name);
o.dates = dates(1,1):dates(1,1)+(nobs(o)-1); o.dates = dates(1,1):dates(1,1)+(nobs(o)-1);
o.ops = cell(length(o.name), 1); o.ops = cell(length(o.name), 1);
o.tags = struct();
elseif isstruct(varargin{1}) elseif isstruct(varargin{1})
o = struct2dseries(varargin{1}); o = struct2dseries(varargin{1});
end end
...@@ -105,26 +87,16 @@ methods ...@@ -105,26 +87,16 @@ methods
% Instantiate dseries object with a data file and force the initial date to % Instantiate dseries object with a data file and force the initial date to
% be as given by the second input argument (initial period represented % be as given by the second input argument (initial period represented
% with a dates object). % with a dates object).
[~, data, varlist, tex, ops, tags] = load_data(varargin{1}); [~, o.data, o.name, o.tex, o.ops, o.tags] = load_data(varargin{1});
o.data = data;
o.name = varlist;
o.dates = varargin{2}:varargin{2}+(nobs(o)-1); o.dates = varargin{2}:varargin{2}+(nobs(o)-1);
o.tex = tex;
o.ops = ops;
o.tags = tags;
return return
end end
if isequal(nargin,2) && ischar(varargin{1}) && ischar(varargin{2}) && isdate(varargin{2}) if isequal(nargin,2) && ischar(varargin{1}) && ischar(varargin{2}) && isdate(varargin{2})
% Instantiate dseries object with a data file and force the initial date to % Instantiate dseries object with a data file and force the initial date to
% be as given by the second input argument (initial period represented with a % be as given by the second input argument (initial period represented with a
% string). % string).
[~, data, varlist, tex, ops, tags] = load_data(varargin{1}); [~, o.data, o.name, o.tex, o.ops, o.tags] = load_data(varargin{1});
o.data = data;
o.name = varlist;
o.dates = dates(varargin{2}):dates(varargin{2})+(nobs(o)-1); o.dates = dates(varargin{2}):dates(varargin{2})+(nobs(o)-1);
o.tex = tex;
o.ops = ops;
o.tags = tags;
return return
end end
a = varargin{1}; a = varargin{1};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment