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. In this case, 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. In this case, the converted value 0018 % is stored back in the specified field, the original value is 0019 % saved for later use and the updated case struct is returned. 0020 % If FIELD is a cell array of strings, they specify nested fields. 0021 % 0022 % The 3rd and optional 4th arguments are simply passed along to 0023 % the call to E2I_DATA. 0024 % 0025 % Examples: 0026 % mpc = e2i_field(mpc, {'reserves', 'cost'}, 'gen'); 0027 % 0028 % Reorders rows of mpc.reserves.cost to match internal generator 0029 % ordering. 0030 % 0031 % mpc = e2i_field(mpc, {'reserves', 'zones'}, 'gen', 2); 0032 % 0033 % Reorders columns of mpc.reserves.zones to match internal 0034 % generator ordering. 0035 % 0036 % See also I2E_FIELD, E2I_DATA, EXT2INT. 0037 0038 % MATPOWER 0039 % $Id: e2i_field.m,v 1.1 2011/11/09 21:32:13 cvs Exp $ 0040 % by Ray Zimmerman, PSERC Cornell 0041 % Copyright (c) 2009-2011 by Power System Engineering Research Center (PSERC) 0042 % 0043 % This file is part of MATPOWER. 0044 % See http://www.pserc.cornell.edu/matpower/ for more info. 0045 % 0046 % MATPOWER is free software: you can redistribute it and/or modify 0047 % it under the terms of the GNU General Public License as published 0048 % by the Free Software Foundation, either version 3 of the License, 0049 % or (at your option) any later version. 0050 % 0051 % MATPOWER is distributed in the hope that it will be useful, 0052 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0053 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0054 % GNU General Public License for more details. 0055 % 0056 % You should have received a copy of the GNU General Public License 0057 % along with MATPOWER. If not, see <http://www.gnu.org/licenses/>. 0058 % 0059 % Additional permission under GNU GPL version 3 section 7 0060 % 0061 % If you modify MATPOWER, or any covered work, to interface with 0062 % other modules (such as MATLAB code and MEX-files) available in a 0063 % MATLAB(R) or comparable environment containing parts covered 0064 % under other licensing terms, the licensors of MATPOWER grant 0065 % you additional permission to convey the resulting work. 0066 0067 if nargin < 4 0068 dim = 1; 0069 end 0070 if ischar(field) 0071 mpc.order.ext.(field) = mpc.(field); 0072 mpc.(field) = e2i_data(mpc, mpc.(field), ordering, dim); 0073 else %% iscell(field) 0074 for k = 1:length(field) 0075 s(k).type = '.'; 0076 s(k).subs = field{k}; 0077 end 0078 mpc.order.ext = subsasgn(mpc.order.ext, s, subsref(mpc, s)); 0079 mpc = subsasgn(mpc, s, ... 0080 e2i_data(mpc, subsref(mpc, s), ordering, dim) ); 0081 end