1function [i_var, nvar, index_uniques] = varlist_indices(sublist, list) 2 3% returns the indices of a list of endogenous variables 4% 5% INPUT 6% sublist [cell of char arrays] sublist of variables 7% list [cell of char arrays] list of variables 8% 9% OUTPUT 10% i_var variable indices in M_.endo_names 11% nvar number of variables in varlist 12% index_uniques indices of unique elements in varlist 13% 14% SPECIAL REQUIREMENTS 15% none 16 17% Copyright (C) 2010-2018 Dynare Team 18% 19% This file is part of Dynare. 20% 21% Dynare is free software: you can redistribute it and/or modify 22% it under the terms of the GNU General Public License as published by 23% the Free Software Foundation, either version 3 of the License, or 24% (at your option) any later version. 25% 26% Dynare is distributed in the hope that it will be useful, 27% but WITHOUT ANY WARRANTY; without even the implied warranty of 28% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29% GNU General Public License for more details. 30% 31% You should have received a copy of the GNU General Public License 32% along with Dynare. If not, see <http://www.gnu.org/licenses/>. 33 34if isempty(sublist) 35 check = []; 36 i_var = []; 37else 38 [check, i_var] = ismember(sublist, list); 39end 40 41if ~all(check) 42 k = find(~check); 43 str = 'The following symbols are not endogenous variables:'; 44 for ii = 1:length(k) 45 str = sprintf('%s %s', str, sublist{k(ii)}); 46 end 47 error(str) 48end 49 50nvar = length(i_var); 51[~, index_uniques, ~] = unique(i_var, 'first'); 52index_uniques = sort(index_uniques); 53i_var_unique = i_var(index_uniques); 54 55if length(i_var_unique)~=nvar 56 k = find(~ismember(1:nvar,index_uniques)); 57 str = 'The following symbols are specified twice in the variable list and are considered only once:'; 58 for ii = 1:length(k) 59 str = sprintf('%s %s', str, sublist{k(ii)}); 60 end 61 warning('%s\n', str) 62 i_var = i_var_unique; 63 nvar = length(i_var); 64end