You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Matlab 2013a转2022b代码生成:命名常量硬编码问题排查

Matlab 2013a到2022b代码升级:常量块硬编码问题排查

因工具链及依赖变更,我们尝试将Matlab 2013a中的自动生成代码升级至Matlab 2022b版本。为此,我们打开旧项目的代码生成配置参数窗口记录所有设置,并通过以下脚本将其应用到Matlab 2022b默认的ERT代码生成项目中:

function [] = setCodeGenSettings2022(cs)
%%%% Mainly to set all configs to match 2013 codegen project setting,
%%%% starting from normal template.
% Data Type Replacement
set_param(cs,'EnableUserReplacementTypes','on'); 
struc = get_param(cs,'ReplacementTypes');
struc.double = '***_real_T';
struc.single = '***_real32_T';
struc.int32 = '***_int32_T';
struc.int16 = '***_int16_T';
struc.int8 = '***_int8_T';
struc.uint32 = '***_uint32_T';
struc.uint16 = '***_uint16_T';
struc.uint8 = '***_uint8_T';
struc.boolean = '***_bolean_T';
set_param(cs,'ReplacementTypes',struc);
% Code Placement 
set_param(cs,'ERTFilePackagingFormat','Modular'); 
% Templates
%%No Tomcat_code_template.cgt available, we use the default
%%ert_code_template.cgt.2013-2022 Diff
% Verification
%%Exactly the same
% Code Style
%%2013-2022 Diff
set_param(cs,'SuppressUnreachableDefaultCases','off')
set_param(cs,'ConvertIfToSwitch','off')
%%2022 New
%%set_param(cs,'PreserveStaticInFcnDecls','true') %% Doesn't exist in 2013,
%%but seems useful.
% Interface
%%2013-2022 Diff
set_param(cs,'SupportNonFinite','off')
set_param(cs,'SupportComplex','off')
set_param(cs, 'CodeInterfacePackaging', 'Reusable function') 
set_param(cs, 'RootIOFormat', 'Structure reference')
% Custom Code
%%Exactly the same
% Identifier
%%Exactly the same
% Comments
%%2013-2022 Diff
set_param(cs, 'StateflowObjectComments', 'on') ;
set_param(cs, 'ShowEliminatedStatement', 'off') ; 
set_param(cs, 'ForceParamTrailComments', 'off') ; 
set_param(cs, 'OperatorAnnotations', 'off') ; 
%%2022 New
%%Kept Simulink block Description,Simulink Data Object and State flow
%%Object Description. Seems Relevant.
% set_param(cs, 'InsertBlockDesc', 'off') ;
% set_param(cs, 'SimulinkDataObjDesc', 'off') ;
% set_param(cs, 'SFDataObjDesc', 'off') ;
% Report
%%Exactly the same
% Optimization
%%2013-2022 Diff
set_param(cs,'DefaultParameterBehavior','Inline');
set_param(cs,'OptimizationCustomize','on');
set_param(cs,'DifferentSizesBufferReuse','off');
set_param(cs,'GlobalVariableUsage','None');
set_param(cs,'OptimizeBlockOrder','off');
% Code Generation - Main
%%2013-2022 Diff
set_param(cs,'PackageGeneratedCodeAndArtifacts','on');
set_param(cs,'BuildConfiguration','Faster Runs')
set_param(cs,'ObjectivePriorities', 'MISRA C:2012 guidelines')
end

但目前遇到唯一问题:部分Simulink命名常量块(参数)在之前的C代码中是变量参数,现在却被保存为硬编码常量。请问该问题出现的原因是什么?是遗漏了哪个配置参数选项,还是其他因素?恳请提供排查建议。

代码对比图1:
代码对比图1

代码对比图2:
代码对比图2

另外,我已在MathWorks社区提出相同问题。

内容的提问来源于stack exchange,提问作者Weltgeist

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 22:30:31