I2E_FIELD Converts fields of MPC from internal to external bus numbering. MPC = I2E_FIELD(MPC, FIELD, ORDERING) MPC = I2E_FIELD(MPC, FIELD, ORDERING, DIM) For a case struct using internal indexing, this function can be used to convert other data structures as well by passing in 2 or 3 extra parameters in addition to the case struct. The 2nd argument is a string or cell array of strings, specifying a field in the case struct whose value should be converted by a corresponding call to I2E_DATA. The field can contain either a numeric or a cell array. The corresponding OLDVAL is taken from where it was stored by EXT2INT in MPC.ORDER.EXT and the updated case struct is returned. If FIELD is a cell array of strings, they specify nested fields. The 3rd and optional 4th arguments are simply passed along to the call to I2E_DATA. Examples: mpc = i2e_field(mpc, {'reserves', 'cost'}, 'gen'); Reorders rows of mpc.reserves.cost to match external generator ordering. mpc = i2e_field(mpc, {'reserves', 'zones'}, 'gen', 2); Reorders columns of mpc.reserves.zones to match external generator ordering. See also E2I_FIELD, I2E_DATA, INT2EXT.
0001 function mpc = i2e_field(mpc, field, ordering, dim) 0002 %I2E_FIELD Converts fields of MPC from internal to external bus numbering. 0003 % 0004 % MPC = I2E_FIELD(MPC, FIELD, ORDERING) 0005 % MPC = I2E_FIELD(MPC, FIELD, ORDERING, DIM) 0006 % 0007 % For a case struct using internal indexing, this function can be 0008 % used to convert other data structures as well by passing in 2 or 3 0009 % extra parameters in addition to the case struct. 0010 % 0011 % The 2nd argument is a string or cell array of strings, specifying 0012 % a field in the case struct whose value should be converted by 0013 % a corresponding call to I2E_DATA. The field can contain either a 0014 % numeric or a cell array. The corresponding OLDVAL is taken from 0015 % where it was stored by EXT2INT in MPC.ORDER.EXT and the updated 0016 % case struct is returned. If FIELD is a cell array of strings, 0017 % they specify nested fields. 0018 % 0019 % The 3rd and optional 4th arguments are simply passed along to 0020 % the call to I2E_DATA. 0021 % 0022 % Examples: 0023 % mpc = i2e_field(mpc, {'reserves', 'cost'}, 'gen'); 0024 % 0025 % Reorders rows of mpc.reserves.cost to match external generator 0026 % ordering. 0027 % 0028 % mpc = i2e_field(mpc, {'reserves', 'zones'}, 'gen', 2); 0029 % 0030 % Reorders columns of mpc.reserves.zones to match external 0031 % generator ordering. 0032 % 0033 % See also E2I_FIELD, I2E_DATA, INT2EXT. 0034 0035 % MATPOWER 0036 % $Id: i2e_field.m 2421 2014-11-12 20:49:31Z ray $ 0037 % by Ray Zimmerman, PSERC Cornell 0038 % Copyright (c) 2009-2011 by Power System Engineering Research Center (PSERC) 0039 % 0040 % This file is part of MATPOWER. 0041 % See http://www.pserc.cornell.edu/matpower/ for more info. 0042 % 0043 % MATPOWER is free software: you can redistribute it and/or modify 0044 % it under the terms of the GNU General Public License as published 0045 % by the Free Software Foundation, either version 3 of the License, 0046 % or (at your option) any later version. 0047 % 0048 % MATPOWER is distributed in the hope that it will be useful, 0049 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0050 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0051 % GNU General Public License for more details. 0052 % 0053 % You should have received a copy of the GNU General Public License 0054 % along with MATPOWER. If not, see <http://www.gnu.org/licenses/>. 0055 % 0056 % Additional permission under GNU GPL version 3 section 7 0057 % 0058 % If you modify MATPOWER, or any covered work, to interface with 0059 % other modules (such as MATLAB code and MEX-files) available in a 0060 % MATLAB(R) or comparable environment containing parts covered 0061 % under other licensing terms, the licensors of MATPOWER grant 0062 % you additional permission to convey the resulting work. 0063 0064 if nargin < 4 0065 dim = 1; 0066 end 0067 if ischar(field) 0068 mpc.order.int.(field) = mpc.(field); 0069 mpc.(field) = i2e_data(mpc, mpc.(field), ... 0070 mpc.order.ext.(field), ordering, dim); 0071 else %% iscell(field) 0072 for k = 1:length(field) 0073 s(k).type = '.'; 0074 s(k).subs = field{k}; 0075 end 0076 if ~isfield(mpc.order, 'int') 0077 mpc.order.int = []; 0078 end 0079 mpc.order.int = subsasgn(mpc.order.int, s, subsref(mpc, s)); 0080 mpc = subsasgn(mpc, s, i2e_data(mpc, subsref(mpc, s), ... 0081 subsref(mpc.order.ext, s), ordering, dim)); 0082 end