Fixed issue with overloaded struct function.

Created instead a new function dseries2struct, which can be called as:

>> o = dseries(randn(10,2));
>> s = o.struct();

Also

 + Added a routine to create a dseries object from a structure (if all
 required field are available).

 + Added the possibility to instantiate a dseries object from a structure.
parent d2481c5a
......@@ -98,6 +98,8 @@ methods
o.dates = dates(1,1):dates(1,1)+(nobs(o)-1);
o.ops = cell(length(o.name), 1);
o.tags = struct();
elseif isstruct(varargin{1})
o = struct2dseries(varargin{1});
end
case {2,3,4}
if isequal(nargin,2) && ischar(varargin{1}) && isdates(varargin{2})
......
function o = resetopts(o, ops)
% Redefine ops member.
% Copyright (C) 2017 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/>.
o.ops = ops;
\ No newline at end of file
function o = resettags(o, tags)
% Redefine tags member.
% Copyright (C) 2017 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/>.
o.tags = tags;
\ No newline at end of file
......@@ -111,6 +111,8 @@ switch S(1).type
else
error('dseries::subsref: Call to save method must come in last position!')
end
case 'struct'
B = dseries2struct(A);
case {'baxter_king_filter', 'baxter_king_filter_', ...
'cumsum','cumsum_', ...
'insert', ...
......@@ -143,7 +145,8 @@ switch S(1).type
'firstdate', ...
'firstobservedperiod', ...
'lastobservedperiod', ...
'lineartrend'}
'lineartrend', ...
'resetops', 'resettags'}
if length(S)>1 && isequal(S(2).type,'()')
if isempty(S(2).subs)
B = feval(S(1).subs,A);
......
......@@ -40,7 +40,8 @@ p = {'/read'; ...
'/utilities/from'; ...
'/utilities/print'; ...
'/utilities/variables'; ...
'/utilities/cumulate'};
'/utilities/cumulate'; ...
'/utilities/struct'};
% Add missing routines if dynare is not in the path
if ~exist('demean','file')
......
function p = struct(o)
function p = dseries2struct(o)
% Converts dseries object to structure.
......
function o = struct2dseries(s)
% Converts structure to dseries object.
% Copyright (C) 2017 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/>.
missingfields = setdiff({'data', 'dates', 'name', 'tex', 'ops', 'tags'}, fieldnames(s));
if isempty(missingfields)
if s.dates.freq==1
time = s.dates.time(1);
else
time = s.dates.time(1,:);
end
o = dseries(s.data, dates(s.dates.freq, time), s.name, s.tex);
o.resetops(s.ops);
o.resettags(s.tags);
else
error('Missing field ins structure: %s\n', missingfields)
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment