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 % Copyright (c) 2008-2015 by Power System Engineering Research Center (PSERC) 0025 % by Ray Zimmerman, PSERC Cornell 0026 % 0027 % $Id: getN.m 2644 2015-03-11 19:34:22Z ray $ 0028 % 0029 % This file is part of MATPOWER. 0030 % Covered by the 3-clause BSD License (see LICENSE file for details). 0031 % See http://www.pserc.cornell.edu/matpower/ for more info. 0032 0033 if nargin < 3 0034 N = om.(selector).N; 0035 else 0036 if isfield(om.(selector).idx.N, name) 0037 if nargin < 4 0038 idx = {}; 0039 end 0040 s1 = substruct('.', name, '()', idx); 0041 N = subsref(om.(selector).idx.N, s1); 0042 else 0043 N = 0; 0044 end 0045 end