Home > matlab > varlist_indices.m

varlist_indices

PURPOSE ^

function [i_var,nvar] = varlist_indices(sublist,list)

SYNOPSIS ^

function [i_var,nvar] = varlist_indices(sublist,list)

DESCRIPTION ^

 function [i_var,nvar] = varlist_indices(sublist,list)
 returns the indices of a list of endogenous variables

 INPUT
   sublist:    sublist of variables
   list:       list of variables 

 OUTPUT
   i_var:      variable indices in M_.endo_names
   nvar:       number of variables in varlist

 SPECIAL REQUIREMENTS
    none

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [i_var,nvar] = varlist_indices(sublist,list)
0002 % function [i_var,nvar] = varlist_indices(sublist,list)
0003 % returns the indices of a list of endogenous variables
0004 %
0005 % INPUT
0006 %   sublist:    sublist of variables
0007 %   list:       list of variables
0008 %
0009 % OUTPUT
0010 %   i_var:      variable indices in M_.endo_names
0011 %   nvar:       number of variables in varlist
0012 %
0013 % SPECIAL REQUIREMENTS
0014 %    none
0015 
0016 % Copyright (C) 2010-2011 Dynare Team
0017 %
0018 % This file is part of Dynare.
0019 %
0020 % Dynare is free software: you can redistribute it and/or modify
0021 % it under the terms of the GNU General Public License as published by
0022 % the Free Software Foundation, either version 3 of the License, or
0023 % (at your option) any later version.
0024 %
0025 % Dynare is distributed in the hope that it will be useful,
0026 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0027 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0028 % GNU General Public License for more details.
0029 %
0030 % You should have received a copy of the GNU General Public License
0031 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0032 
0033 % In Octave, ismember() doesn't operate on character arrays
0034 if ~exist('OCTAVE_VERSION')
0035     [check,i_var] = ismember(sublist,list,'rows');
0036 else
0037     check = [];
0038     i_var = [];
0039     for i = 1:rows(sublist)
0040         tmp = strmatch(deblank(sublist(i,:)), list, 'exact');
0041         if isempty(tmp)
0042             check = [ check; 0 ];
0043         else
0044             check = [ check; 1 ];
0045             i_var = [ i_var; tmp ];
0046         end
0047     end
0048 end
0049 
0050 nvar = length(i_var);
0051 
0052 if ~all(check)
0053     k = find(~check);
0054     tempstring = 'The following symbols are not endogenous variables: ';
0055     for ii = 1:length(k)
0056         tempstring = [ tempstring, deblank(sublist(k(ii),:)), ' ' ];
0057     end
0058     error(tempstring)
0059 end

Generated on Wed 23-May-2012 02:40:54 by m2html © 2005