GETPROFILES Loads profiles, optionally updating 'rows' via an index mapping. PROFILES = GETPROFILES(PROFILESI); PROFILES = GETPROFILES(PROFILESI, PROFILES0); PROFILES = GETPROFILES(PROFILESI, IDX); PROFILES = GETPROFILES(PROFILESI, PROFILES0, IDX); Loads a profile or set of profiles from a struct, MAT-file or M-file, optionally using the N-dimensional index vector IDX to modify any non-zero values in ROWS fields so that the corresponding ROWS field in the returned PROFILES is equal to IDX(ROWS). This makes it easy to use profiles defined for a particular set of generators, for example, that are added to a case as a group as in the example below. Inputs: PROFILESI : a PROFILE struct or the name of an M-file or MAT-file that returns one. See IDX_PROFILE for details. PROFILES0 : (optional) a profiles struct to which the newly loaded profiles specified in PROFILESI will be appended. IDX : (optional) N dimensional index vector used to map non-zero values in ROWS fields. Output: PROFILES : Resulting profile struct Example: Load a MATPOWER case, add some wind generators, with a profile that applies only to the rows of the added wind units. mpc = loadcase('mycase'); xgd = loadxgendata('myxgendata'); [iwind, mpc, xgd] = addwind('mywindunits', mpc, xgd); profiles = getprofiles('mywindprofile', iwind); md = loadmd(mpc, 'mytransmat', xgd, [], [], profiles); See also APPLY_PROFILE, IDX_PROFILE.
0001 function profiles = getprofiles(profilesi, profiles0, idx) 0002 %GETPROFILES Loads profiles, optionally updating 'rows' via an index mapping. 0003 % 0004 % PROFILES = GETPROFILES(PROFILESI); 0005 % PROFILES = GETPROFILES(PROFILESI, PROFILES0); 0006 % PROFILES = GETPROFILES(PROFILESI, IDX); 0007 % PROFILES = GETPROFILES(PROFILESI, PROFILES0, IDX); 0008 % 0009 % Loads a profile or set of profiles from a struct, MAT-file or M-file, 0010 % optionally using the N-dimensional index vector IDX to modify any 0011 % non-zero values in ROWS fields so that the corresponding ROWS 0012 % field in the returned PROFILES is equal to IDX(ROWS). This makes it 0013 % easy to use profiles defined for a particular set of generators, for 0014 % example, that are added to a case as a group as in the example below. 0015 % 0016 % Inputs: 0017 % PROFILESI : a PROFILE struct or the name of an M-file 0018 % or MAT-file that returns one. See IDX_PROFILE for details. 0019 % PROFILES0 : (optional) a profiles struct to which the newly 0020 % loaded profiles specified in PROFILESI will be appended. 0021 % IDX : (optional) N dimensional index vector used to map non-zero 0022 % values in ROWS fields. 0023 % 0024 % Output: 0025 % PROFILES : Resulting profile struct 0026 % 0027 % Example: Load a MATPOWER case, add some wind generators, with a 0028 % profile that applies only to the rows of the added wind 0029 % units. 0030 % 0031 % mpc = loadcase('mycase'); 0032 % xgd = loadxgendata('myxgendata'); 0033 % [iwind, mpc, xgd] = addwind('mywindunits', mpc, xgd); 0034 % profiles = getprofiles('mywindprofile', iwind); 0035 % md = loadmd(mpc, 'mytransmat', xgd, [], [], profiles); 0036 % 0037 % See also APPLY_PROFILE, IDX_PROFILE. 0038 0039 % MOST 0040 % Copyright (c) 2012-2016, Power Systems Engineering Research Center (PSERC) 0041 % by Ray Zimmerman, PSERC Cornell 0042 % 0043 % This file is part of MOST. 0044 % Covered by the 3-clause BSD License (see LICENSE file for details). 0045 % See https://github.com/MATPOWER/most for more info. 0046 0047 %% process input args 0048 if nargin < 2 0049 profiles0 = []; 0050 idx = []; 0051 elseif nargin < 3 0052 if ~isstruct(profiles0) && ~isempty(profiles0) 0053 idx = profiles0; 0054 profiles0 = []; 0055 else 0056 idx = []; 0057 end 0058 end 0059 0060 %% load the profiles 0061 fields = {'type', 'table', 'rows', 'col', 'chgtype', 'values'}; 0062 profiles = loadgenericdata(profilesi, 'struct', fields, 'profiles'); 0063 0064 %% use idx to map rows 0065 if ~isempty(idx) 0066 n = length(idx); 0067 for p = 1:length(profiles) 0068 k = find(profiles(p).rows); 0069 if k > 0 0070 if max(profiles(p).rows(k)) <= n 0071 profiles(p).rows(k) = idx(profiles(p).rows(k)); 0072 else 0073 error('getprofiles: to map ROWS using IDX, ROWS must not contain values exceeding LENGTH(IDX) (%d)', n); 0074 end 0075 end 0076 end 0077 end 0078 0079 %% stack profiles 0080 if ~isempty(profiles0) 0081 profiles = [profiles0; profiles]; 0082 end