Main Content

rtw.codegenObjectives.Objective

自定义代码生成目标

说明

使用代码生成目标来指定一组检查和参数,以便代码生成顾问进行验证。

创建对象

描述

示例

rtw.codegenObjectives.Objective(newObjID) 创建一个具有指定的标识符的新代码生成目标。

rtw.codegenObjectives.Objective(newObjID, baseObjID) 基于指定的现有代码生成目标创建一个代码生成目标。现有目标必须在代码生成顾问中注册。

输入参量

全部展开

新目标的标识符,指定为字符向量或字符串标量。

新目标所基于的现有目标的标识符,指定为字符向量或字符串标量。

对象函数

setObjectiveNameSpecify objective name
addCheckAdd check to code generation objective
addParamAdd parameters to code generation objective
excludeCheckExclude check from code generation objective
modifyInheritedParamModify inherited parameter values in code generation objective
removeInheritedCheckRemove inherited check from objective
removeInheritedParamRemove inherited parameter from objective
register在代码生成顾问中注册目标

示例

全部折叠

创建一个名为 Reduced RAM Example 的自定义目标,该目标运行检查并验证参数值,确认配置模型为生成代码已减少使用 RAM。

创建文件 sl_customization.m 以包含用于创建自定义目标的回调函数。

function sl_customization(cm)
%SL_CUSTOMIZATION objective customization callback

objCustomizer = cm.ObjectiveCustomizer;
index = objCustomizer.addCallbackObjFcn(@addObjectives);
objCustomizer.callbackFcn{index}();

end

addObjectives 函数中创建和配置目标。设置目标的名称,并添加检查和参数进行验证。然后在代码生成顾问中注册该目标。

function addObjectives

% Create the custom objective
obj = rtw.codegenObjectives.Objective('ex_ram_1');
setObjectiveName(obj, 'Reduce RAM Example');

% Add parameters to the objective
addParam(obj, 'InlineParams', 'on');
addParam(obj, 'BooleanDataType', 'on');
addParam(obj, 'OptimizeBlockIOStorage', 'on');
addParam(obj, 'EnhancedBackFolding', 'on');
addParam(obj, 'BooleansAsBitfields', 'on');

% Add additional checks to the objective
% The Code Generation Advisor automatically includes 'Check model
% configuration settings against code generation objectives' in every
% objective.
addCheck(obj, 'Identify unconnected lines, input ports, and output ports');
addCheck(obj, 'Check model and local libraries for updates');

%Register the objective
register(obj);

end

版本历史记录

在 R2009a 中推出