GETN Returns the number of variables, constraints or cost rows. N = GETN(OM, SELECTOR) N = GETN(OM, SELECTOR, NAME) N = GETN(OM, SELECTOR, NAME, IDX) Returns either the total number of variables/constraints/cost rows or the number corresponding to a specified named block. Examples: N = getN(om, 'var') : total number of variables N = getN(om, 'lin') : total number of linear constraints N = getN(om, 'nln') : total number of nonlinear constraints N = getN(om, 'cost') : total number of cost rows (in N) N = getN(om, 'var', name) : number of variables in named set N = getN(om, 'lin', name) : number of linear constraints in named set N = getN(om, 'nln', name) : number of nonlinear cons. in named set N = getN(om, 'cost', name) : number of cost rows (in N) in named set N = getN(om, 'var', name, idx) : number of variables in indexed named set See also OPT_MODEL.
0001 function N = getN(om, selector, name, idx) 0002 %GETN Returns the number of variables, constraints or cost rows. 0003 % N = GETN(OM, SELECTOR) 0004 % N = GETN(OM, SELECTOR, NAME) 0005 % N = GETN(OM, SELECTOR, NAME, IDX) 0006 % 0007 % Returns either the total number of variables/constraints/cost rows 0008 % or the number corresponding to a specified named block. 0009 % 0010 % Examples: 0011 % N = getN(om, 'var') : total number of variables 0012 % N = getN(om, 'lin') : total number of linear constraints 0013 % N = getN(om, 'nln') : total number of nonlinear constraints 0014 % N = getN(om, 'cost') : total number of cost rows (in N) 0015 % N = getN(om, 'var', name) : number of variables in named set 0016 % N = getN(om, 'lin', name) : number of linear constraints in named set 0017 % N = getN(om, 'nln', name) : number of nonlinear cons. in named set 0018 % N = getN(om, 'cost', name) : number of cost rows (in N) in named set 0019 % N = getN(om, 'var', name, idx) : number of variables in indexed named set 0020 % 0021 % See also OPT_MODEL. 0022 0023 % MATPOWER 0024 % $Id: getN.m 2048 2012-05-03 12:59:07Z cvs $ 0025 % by Ray Zimmerman, PSERC Cornell 0026 % Copyright (c) 2008-2012 by Power System Engineering Research Center (PSERC) 0027 % 0028 % This file is part of MATPOWER. 0029 % See http://www.pserc.cornell.edu/matpower/ for more info. 0030 % 0031 % MATPOWER is free software: you can redistribute it and/or modify 0032 % it under the terms of the GNU General Public License as published 0033 % by the Free Software Foundation, either version 3 of the License, 0034 % or (at your option) any later version. 0035 % 0036 % MATPOWER is distributed in the hope that it will be useful, 0037 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0038 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0039 % GNU General Public License for more details. 0040 % 0041 % You should have received a copy of the GNU General Public License 0042 % along with MATPOWER. If not, see <http://www.gnu.org/licenses/>. 0043 % 0044 % Additional permission under GNU GPL version 3 section 7 0045 % 0046 % If you modify MATPOWER, or any covered work, to interface with 0047 % other modules (such as MATLAB code and MEX-files) available in a 0048 % MATLAB(R) or comparable environment containing parts covered 0049 % under other licensing terms, the licensors of MATPOWER grant 0050 % you additional permission to convey the resulting work. 0051 0052 if nargin < 3 0053 N = om.(selector).N; 0054 else 0055 if isfield(om.(selector).idx.N, name) 0056 if nargin < 4 0057 idx = {}; 0058 end 0059 s1 = substruct('.', name, '()', idx); 0060 N = subsref(om.(selector).idx.N, s1); 0061 else 0062 N = 0; 0063 end 0064 end