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 % Copyright (c) 2009-2015 by Power System Engineering Research Center (PSERC) 0037 % by Ray Zimmerman, PSERC Cornell 0038 % 0039 % $Id: i2e_field.m 2644 2015-03-11 19:34:22Z ray $ 0040 % 0041 % This file is part of MATPOWER. 0042 % Covered by the 3-clause BSD License (see LICENSE file for details). 0043 % See http://www.pserc.cornell.edu/matpower/ for more info. 0044 0045 if nargin < 4 0046 dim = 1; 0047 end 0048 if ischar(field) 0049 mpc.order.int.(field) = mpc.(field); 0050 mpc.(field) = i2e_data(mpc, mpc.(field), ... 0051 mpc.order.ext.(field), ordering, dim); 0052 else %% iscell(field) 0053 for k = 1:length(field) 0054 s(k).type = '.'; 0055 s(k).subs = field{k}; 0056 end 0057 if ~isfield(mpc.order, 'int') 0058 mpc.order.int = []; 0059 end 0060 mpc.order.int = subsasgn(mpc.order.int, s, subsref(mpc, s)); 0061 mpc = subsasgn(mpc, s, i2e_data(mpc, subsref(mpc, s), ... 0062 subsref(mpc.order.ext, s), ordering, dim)); 0063 end