pop_.m 1.84 KB
Newer Older
1 2 3 4
function [o, id] = pop_(o, a) % --*-- Unitary tests --*--

% Removes a variable from a dseries object.
%
Stéphane Adjemian's avatar
Stéphane Adjemian committed
5
% INPUTS
6 7 8
% - o   [dseries]  T observations and N variables.
% - a   [string]   Name of the variable to be removed.
%
Stéphane Adjemian's avatar
Stéphane Adjemian committed
9
% OUTPUTS
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
% - o   [dseries]  T observations and N-1 variables.

% Copyright (C) 2013-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/>.

if nargin<2
    % Removes the last variable
    id = vobs(o);
else
    id = find(strcmp(a, o.name));
end

if isempty(id)
    id = 0;
    return
end

o.data(:,id) = [];
o.name(id) = [];
o.tex(id) = [];
44
o.ops(id) = [];
45 46 47 48
otagnames = fieldnames(o.tags);
for i=1:length(otagnames)
    o.tags.(otagnames{i})(id) = []; 
end
49 50 51 52 53 54 55 56 57 58 59

%@test:1
%$ % Define a datasets.
%$ A = rand(10,3);
%$
%$ % Define names
%$ A_name = {'A1';'A2';'A3'};
%$
%$ % Instantiate a time series object.
%$ try
%$    ts1 = dseries(A,[],A_name,[]);
60 61 62 63
%$    ts1.tag('type');
%$    ts1.tag('type', 'A1', 1);
%$    ts1.tag('type', 'A2', 2);
%$    ts1.tag('type', 'A3', 3);
64 65 66 67 68 69
%$    ts1.pop_('A2');
%$    t(1) = 1;
%$ catch
%$    t(1) = 0;
%$ end
%$
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 76 77
%$ end
%$ T = all(t);
%@eof:1