www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@xregusermod/evalbuild.m

    function Blk = evalbuild(m,sys)
%EVALBUILD Create a simulink diagram for the model
%
%  xregusermod evalbuild method adds an evaluation simulink block to
%  a simulink implementation of a global usermodel.

%  Copyright 2000-2014 The MathWorks, Inc. and Ford Global Technologies, Inc.


% Add the container block that holds parameters
Blk = add_block('mbcSLModels/TwoStage/userModEval',[sys,'/userModEval']);
set_param(Blk,'linkstatus','none');
AddVariablesToUserdata(Blk,{'P'},{double(m)});

% Create user-defined model block
BlkUser = slblock(m, Blk);

if ~isempty(BlkUser)
    % Move block to between ports
    pos = get_param(BlkUser, 'position');
    [~, width, height] = LTRB2Centre(pos);
    newpos = Centre2LTRB([200 70], width, height);
    set_param(BlkUser, 'position', newpos);
    
    % Connect up the ports to the new block
    nm = get_param(BlkUser, 'name');
    add_line(Blk, 'Parameters/1', [nm '/1'], 'Autorouting', 'on');
    add_line(Blk, 'X/1', [nm '/2'], 'Autorouting', 'on');
    add_line(Blk, [nm '/1'], 'Y/1', 'Autorouting', 'on'); 
end