www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@conswitch/slSetParameters.m

    function slSetParameters(con, sys)
%SLSETPARAMETERS Set parameters of a Point-by-point constraint Simulink model.
%
%  SLSETPARAMETERS(CON, SYS)
%
%  Each constraint must provide it's own version of PSLGETPARAMETERS. This
%  methods returns a structure with all the required parameters.
%
%  We write this set method separately from the method for getting the
%  parameters so that we may easily change how the blocks store the parameter
%  information.
%
%  See also CONBASE, CONBASE/SLBLOCK, CONBASE/PSLGETPARAMETERS.

%  Copyright 2014 The MathWorks, Inc.


constraintModels = con.ConList;
numSites = size(con.OpPoints,1);
sysName = getfullname(sys);

% cycle through constraints and set the parameters for each one
for i=1:numSites
    ithConSys = sprintf('%s/Constraints/Constraint%d', sysName, i);
    setParametersForSite(constraintModels{i}, ithConSys);
end


function setParametersForSite(con, sys)
% Get up user data structure for this constraint
ud = pslGetParameters(con);

if ~isempty(ud)
    % The initialization command has to get all of the data from the user
    % structure and assign it to the variables that the block is expecting
    fn = fieldnames(ud);
    nFields = length(fn);
    maskInitialization = cell(nFields, 1);
    for i = 1:nFields
        maskInitialization{i} = sprintf('%s = ud.%s; ', fn{i}, fn{i});
    end
    maskInitialization = strcat(...
        'ud = get_param(gcb, ''UserData''); ', ...
        maskInitialization{:});

    % Assign the user data to the block
    set_param(sys, 'UserData', ud);
    set_param(sys, 'UserDataPersistent', 'on');
    set_param(sys, 'MaskInitialization', maskInitialization);
end