E2I_FIELD Converts fields of MPC from external to internal indexing. This function performs several different tasks, depending on the arguments passed. MPC = E2I_FIELD(MPC, FIELD, ORDERING) MPC = E2I_FIELD(MPC, FIELD, ORDERING, DIM) When given a case struct that has already been converted to 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 E2I_DATA. The field can contain either a numeric or a cell array. The converted value is stored back in the specified field, the original value is saved for later use 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 E2I_DATA. Examples: mpc = e2i_field(mpc, {'reserves', 'cost'}, 'gen'); Reorders rows of mpc.reserves.cost to match internal generator ordering. mpc = e2i_field(mpc, {'reserves', 'zones'}, 'gen', 2); Reorders columns of mpc.reserves.zones to match internal generator ordering. See also I2E_FIELD, E2I_DATA, EXT2INT.
0001 function mpc = e2i_field(mpc, field, ordering, dim) 0002 %E2I_FIELD Converts fields of MPC from external to internal indexing. 0003 % 0004 % This function performs several different tasks, depending on the 0005 % arguments passed. 0006 % 0007 % MPC = E2I_FIELD(MPC, FIELD, ORDERING) 0008 % MPC = E2I_FIELD(MPC, FIELD, ORDERING, DIM) 0009 % 0010 % When given a case struct that has already been converted to 0011 % internal indexing, this function can be used to convert other data 0012 % structures as well by passing in 2 or 3 extra parameters in 0013 % addition to the case struct. 0014 % 0015 % The 2nd argument is a string or cell array of strings, specifying 0016 % a field in the case struct whose value should be converted by 0017 % a corresponding call to E2I_DATA. The field can contain either a 0018 % numeric or a cell array. The converted value is stored back in the 0019 % specified field, the original value is saved for later use and the 0020 % updated case struct is returned. If FIELD is a cell array of strings, 0021 % they specify nested fields. 0022 % 0023 % The 3rd and optional 4th arguments are simply passed along to 0024 % the call to E2I_DATA. 0025 % 0026 % Examples: 0027 % mpc = e2i_field(mpc, {'reserves', 'cost'}, 'gen'); 0028 % 0029 % Reorders rows of mpc.reserves.cost to match internal generator 0030 % ordering. 0031 % 0032 % mpc = e2i_field(mpc, {'reserves', 'zones'}, 'gen', 2); 0033 % 0034 % Reorders columns of mpc.reserves.zones to match internal 0035 % generator ordering. 0036 % 0037 % See also I2E_FIELD, E2I_DATA, EXT2INT. 0038 0039 % MATPOWER 0040 % Copyright (c) 2009-2015 by Power System Engineering Research Center (PSERC) 0041 % by Ray Zimmerman, PSERC Cornell 0042 % 0043 % $Id: e2i_field.m 2644 2015-03-11 19:34:22Z ray $ 0044 % 0045 % This file is part of MATPOWER. 0046 % Covered by the 3-clause BSD License (see LICENSE file for details). 0047 % See http://www.pserc.cornell.edu/matpower/ for more info. 0048 0049 if nargin < 4 0050 dim = 1; 0051 end 0052 if ischar(field) 0053 mpc.order.ext.(field) = mpc.(field); 0054 mpc.(field) = e2i_data(mpc, mpc.(field), ordering, dim); 0055 else %% iscell(field) 0056 for k = 1:length(field) 0057 s(k).type = '.'; 0058 s(k).subs = field{k}; 0059 end 0060 mpc.order.ext = subsasgn(mpc.order.ext, s, subsref(mpc, s)); 0061 mpc = subsasgn(mpc, s, ... 0062 e2i_data(mpc, subsref(mpc, s), ordering, dim) ); 0063 end