www.gusucode.com > mbcexpr 工具箱 matlab 源码程序 > mbcexpr/@cgnormfunction/buildsl.m
function [h,pInputs,msg] = buildsl(e,blockname,Sopts) %BUILDSL build simulink block for expression % % [h,p,msg] = buildsl(e,blockname,Sopts) % Copyright 2007-2012 The MathWorks, Inc. and Ford Global Technologies, Inc. msg = ''; switch Sopts.SLType case {1,4} [blk,msg] = standardTable(e,blockname,Sopts,msg); case {2,3} % extrapolating table and ford tables no longer exist error('mbc:cgnormfunction:UnknownTableType',... 'Unknown table type exported') case 5 blk = prelookupTable(e,blockname,Sopts); otherwise error('mbc:cgnormfunction:UnknownTableType',... 'Unknown table type exported') end set_param(blk,'foregroundColor','darkGreen'); h=get_param(blockname,'handle'); pInputs=get(e,'x'); % Helper function that checks table values for non-finite data function [y,warns] = i_checkfinite(y, blockname) if ~all(isfinite(y(:))) warns = sprintf(['Values for %s could not be '... 'exported because they contain NaNs or infs.'], blockname); y = []; else warns = ''; end function [blk,msg] = standardTable(e,blockname,Sopts,msg) blk = add_block('cgeqlib/Function',blockname); if Sopts.WriteCalibration [tblName,msg,T] = storeData(e,blk, blockname); set_param(blockname,... 'InputValues',sprintf('0:%d',length(T)-1),... 'OutputValues',tblName); end function blk = prelookupTable(e,blockname,Sopts) blk = add_block('built-in/Interpolation_n-D',blockname); set_param(blockname,'NumberOfTableDimensions','1'); if Sopts.WriteCalibration tblName = storeData(e,blk, blockname); set_param(blockname,'Table',tblName,... 'Position',[1 1 41 41]); end function [tblName,msg,T] = storeData(e,blk, blockname) [T,msg] = getTableData(e, blockname); tblName = getname(e); % store data in model workspace ws = get_param(bdroot(blk),'ModelWorkspace'); ws.assignin( tblName, T); function [T,msg] = getTableData(e, blockname) T = get(e,'values'); [T,msg] = i_checkfinite(T(:)', blockname);