1function [o, id] = pop_(o, a) % --*-- Unitary tests --*--
2
3% Removes a variable from a dseries object.
4%
5% INPUTS
6% - o   [dseries]  T observations and N variables.
7% - a   [string]   Name of the variable to be removed.
8%
9% OUTPUTS
10% - o   [dseries]  T observations and N-1 variables.
11
12% Copyright (C) 2013-2017 Dynare Team
13%
14% This file is part of Dynare.
15%
16% Dynare is free software: you can redistribute it and/or modify
17% it under the terms of the GNU General Public License as published by
18% the Free Software Foundation, either version 3 of the License, or
19% (at your option) any later version.
20%
21% Dynare is distributed in the hope that it will be useful,
22% but WITHOUT ANY WARRANTY; without even the implied warranty of
23% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24% GNU General Public License for more details.
25%
26% You should have received a copy of the GNU General Public License
27% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
28
29if nargin<2
30    % Removes the last variable
31    id = vobs(o);
32else
33    id = find(strcmp(a, o.name));
34end
35
36if isempty(id)
37    id = 0;
38    return
39end
40
41o.data(:,id) = [];
42o.name(id) = [];
43o.tex(id) = [];
44o.ops(id) = [];
45otagnames = fieldnames(o.tags);
46for i=1:length(otagnames)
47    o.tags.(otagnames{i})(id) = [];
48end
49
50%@test:1
51%$ % Define a datasets.
52%$ A = rand(10,3);
53%$
54%$ % Define names
55%$ A_name = {'A1';'A2';'A3'};
56%$
57%$ % Instantiate a time series object.
58%$ try
59%$    ts1 = dseries(A,[],A_name,[]);
60%$    ts1.tag('type');
61%$    ts1.tag('type', 'A1', 1);
62%$    ts1.tag('type', 'A2', 2);
63%$    ts1.tag('type', 'A3', 3);
64%$    ts1.pop_('A2');
65%$    t(1) = 1;
66%$ catch
67%$    t(1) = 0;
68%$ end
69%$
70%$ if t(1)
71%$    t(2) = dassert(ts1.vobs,2);
72%$    t(3) = dassert(ts1.nobs,10);
73%$    t(4) = dassert(ts1.data,[A(:,1), A(:,3)],1e-15);
74%$    t(5) = dassert(ts1.tags.type, {1;3});
75%$ end
76%$ T = all(t);
77%@eof:1