From b48e0a8d756e8ec57ad28af1d863fe055a8a1f8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Sat, 8 Dec 2012 17:44:50 +0100 Subject: [PATCH] Added set_names method in dynSeries class. --- matlab/@dynSeries/set_names.m | 113 ++++++++++++++++++++++++++++++++++ matlab/@dynSeries/subsref.m | 5 ++ 2 files changed, 118 insertions(+) create mode 100644 matlab/@dynSeries/set_names.m diff --git a/matlab/@dynSeries/set_names.m b/matlab/@dynSeries/set_names.m new file mode 100644 index 000000000..bee843788 --- /dev/null +++ b/matlab/@dynSeries/set_names.m @@ -0,0 +1,113 @@ +function A = set_names(B,varargin) + +%@info: +%! @deftypefn {Function File} {@var{A} =} times (@var{B},@code{varargin}) +%! @anchor{@nSeries/set_names} +%! @sp 1 +%! Specify names of the variables in a @ref{dynSeries} object. +%! @sp 2 +%! @strong{Inputs} +%! @sp 1 +%! @table @ @var +%! @item B +%! Dynare time series object instantiated by @ref{dynSeries}. +%! @item C +%! Dynare time series object instantiated by @ref{dynSeries}. +%! @end table +%! @sp 1 +%! @strong{Outputs} +%! @sp 1 +%! @table @ @var +%! @item A +%! Dynare time series object. +%! @end deftypefn +%@eod: + +% Copyright (C) 2012 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 . + +% AUTHOR(S) stephane DOT adjemian AT univ DASH lemans DOT fr + +n = nargin-1; + +if ~isa(B,'dynSeries') + error(['dynSeries::rename: ' inputname(1) ' must be a dynSeries object!']) +end + +if ~isequal(B.vobs,n) + error(['dynSeries::rename: The number of variables in ' inputname(1) ' does not match the number of declared names!']) +end + +A = B; + +for i=1:A.vobs + if ~isempty(varargin{i}) + A.name(i) = { varargin{i} }; + end +end + +%@test:1 +%$ % Define a datasets. +%$ A = rand(10,3); +%$ +%$ % Define names +%$ A_name = {'A1';'--NA--';'A3'}; +%$ +%$ t = zeros(4,1); +%$ +%$ % Instantiate a time series object. +%$ try +%$ ts1 = dynSeries(A,[],[],[]); +%$ ts2 = set_names(ts1,'A1',[],'A3'); +%$ t(1) = 1; +%$ catch +%$ t = 0; +%$ end +%$ +%$ if length(t)>1 +%$ t(2) = dyn_assert(ts2.vobs,3); +%$ t(3) = dyn_assert(ts2.nobs,10); +%$ t(4) = dyn_assert(ts2.name,A_name); +%$ end +%$ T = all(t); +%@eof:1 + +%@test:2 +%$ % Define a datasets. +%$ A = rand(10,3); +%$ +%$ % Define names +%$ A_name = {'A1';'--NA--';'A3'}; +%$ +%$ t = zeros(4,1); +%$ +%$ % Instantiate a time series object. +%$ try +%$ ts1 = dynSeries(A,[],[],[]); +%$ ts1 = ts1.set_names('A1',[],'A3'); +%$ t(1) = 1; +%$ catch +%$ t = 0; +%$ end +%$ +%$ if length(t)>1 +%$ t(2) = dyn_assert(ts1.vobs,3); +%$ t(3) = dyn_assert(ts1.nobs,10); +%$ t(4) = dyn_assert(ts1.name,A_name); +%$ end +%$ T = all(t); +%@eof:2 diff --git a/matlab/@dynSeries/subsref.m b/matlab/@dynSeries/subsref.m index 66772dec6..1b3958281 100644 --- a/matlab/@dynSeries/subsref.m +++ b/matlab/@dynSeries/subsref.m @@ -131,6 +131,11 @@ if (length(S)==2) && isequal(S(1).subs,'save') && isequal(S(1).type,'.') && iseq return end +if (length(S)==2) && isequal(S(1).subs,'set_names') && isequal(S(1).type,'.') && isequal(S(2).type,'()') + us = set_names(ts,S(2).subs{:}); + return +end + %@test:1