DESCRIBE_IDX Identifies variable, constraint and cost row indices. LABEL = DESCRIBE_IDX(OM, IDX_TYPE, IDXS) Returns strings describing (name and index) the variable, constraint or cost row that corresponds to the indices in IDXS. IDX_TYPE must be one of the following: 'var', 'lin', 'nln', or 'cost', corresponding to indices for variables, linear constraints, non-linear constraints and cost rows, respectively. The return value is a string if IDXS is a scalar, otherwise it is a cell array of strings of the same dimension as IDXS. Examples: label = describe_idx(om, 'var', 87)); labels = describe_idx(om, 'lin', [38; 49; 93])); See also OPT_MODEL.
0001 function label = describe_idx(om, idx_type, idxs) 0002 %DESCRIBE_IDX Identifies variable, constraint and cost row indices. 0003 % LABEL = DESCRIBE_IDX(OM, IDX_TYPE, IDXS) 0004 % 0005 % Returns strings describing (name and index) the variable, constraint 0006 % or cost row that corresponds to the indices in IDXS. IDX_TYPE must be 0007 % one of the following: 'var', 'lin', 'nln', or 'cost', corresponding 0008 % to indices for variables, linear constraints, non-linear constraints 0009 % and cost rows, respectively. The return value is a string if IDXS is 0010 % a scalar, otherwise it is a cell array of strings of the same 0011 % dimension as IDXS. 0012 % 0013 % Examples: 0014 % label = describe_idx(om, 'var', 87)); 0015 % labels = describe_idx(om, 'lin', [38; 49; 93])); 0016 % 0017 % See also OPT_MODEL. 0018 0019 % MATPOWER 0020 % $Id: describe_idx.m 2089 2012-10-01 16:53:09Z cvs $ 0021 % by Ray Zimmerman, PSERC Cornell 0022 % Copyright (c) 2012 by Power System Engineering Research Center (PSERC) 0023 % 0024 % This file is part of MATPOWER. 0025 % See http://www.pserc.cornell.edu/matpower/ for more info. 0026 % 0027 % MATPOWER is free software: you can redistribute it and/or modify 0028 % it under the terms of the GNU General Public License as published 0029 % by the Free Software Foundation, either version 3 of the License, 0030 % or (at your option) any later version. 0031 % 0032 % MATPOWER is distributed in the hope that it will be useful, 0033 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0034 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0035 % GNU General Public License for more details. 0036 % 0037 % You should have received a copy of the GNU General Public License 0038 % along with MATPOWER. If not, see <http://www.gnu.org/licenses/>. 0039 % 0040 % Additional permission under GNU GPL version 3 section 7 0041 % 0042 % If you modify MATPOWER, or any covered work, to interface with 0043 % other modules (such as MATLAB code and MEX-files) available in a 0044 % MATLAB(R) or comparable environment containing parts covered 0045 % under other licensing terms, the licensors of MATPOWER grant 0046 % you additional permission to convey the resulting work. 0047 0048 label = cell(size(idxs)); %% pre-allocate return cell array 0049 for i = 1:length(idxs(:)) 0050 ii = idxs(i); 0051 if ii > om.(idx_type).N 0052 error('@opt_model/describe_idx: index exceeds maximum %s index (%d)', idx_type, om.(idx_type).N); 0053 end 0054 if ii < 1 0055 error('@opt_model/describe_idx: index must be positive'); 0056 end 0057 for k = om.(idx_type).NS:-1:1 0058 name = om.(idx_type).order(k).name; 0059 idx = om.(idx_type).order(k).idx; 0060 if isempty(idx) 0061 if ii >= om.(idx_type).idx.i1.(name) 0062 label{i} = sprintf('%s(%d)', name, ii - om.(idx_type).idx.i1.(name) + 1); 0063 break; 0064 end 0065 else 0066 s = substruct('.', name, '()', idx); 0067 if ii >= subsref(om.(idx_type).idx.i1, s) 0068 idxstr = sprintf('%d', idx{1}); 0069 for j = 2:length(idx) 0070 idxstr = sprintf('%s,%d', idxstr, idx{j}); 0071 end 0072 label{i} = sprintf('%s(%s)(%d)', name, idxstr, ... 0073 ii - subsref(om.(idx_type).idx.i1, s) + 1); 0074 break; 0075 end 0076 end 0077 end 0078 end 0079 if isscalar(idxs) %% return scalar 0080 label = label{1}; 0081 end