一、模型配置的导出与导入
1、模型配置的导出
假设你想要保存模型配置的simulink名称为“pre_set.slx”
open('pre_set');% 打开模型,用于获取模型句柄
currentModelSet = getActiveConfigSet('pre_set')
% 获取模型配置集
saveAs(currentModelSet,'MyConfig')
% 储存当前模型的配置为MyConfig.m,这是一个m函数
部分函数如下:
function cs = MyConfig()
% MATLAB function for configuration set generated on 21-May-2021 09:10:54
% MATLAB version: 9.6.0.1472908 (R2019a) Update 9
cs = Simulink.ConfigSet;
% Original configuration set version: 19.0.0
if cs.versionCompare('19.0.0') < 0
error('Simulink:MFileVersionViolation', 'The version of the target configuration set is older than the original configuration set.');
end
% Original environment character encoding: windows-1252
if ~strcmpi(get_param(0, 'CharacterEncoding'), 'windows-1252')
warning('Simulink:EncodingUnMatched', 'The target character encoding (%s) is different from the original (%s).', get_param(0, 'CharacterEncoding'), 'windows-1252');
end
% Do not change the order of the following commands. There are dependencies between the parameters.
cs.set_param('Name', 'Configuration'); % Name
cs.set_param('Description', ''); % Description
2、模型配置的导入
|-将保存的配置给到开发者的模型
将 MyConfig.m文件,重新复制一份,并重命名为ActiveConfig.m
打开,将代码修改。
修改前代码:
function cs = MyConfig()
% MATLAB function for configuration set generated on 21-May-2021 09:10:54
% MATLAB version: 9.6.0.1472908 (R2019a) Update 9
cs = Simulink.ConfigSet;
% Original configuration set version: 19.0.0
if cs.versionCompare('19.0.0') < 0
error('Simulink:MFileVersionViolation', 'The version of the target configuration set is older than the original configuration set.');
end
修改后代码:
function cs = ActiveConfig(model_name)
% MATLAB function for configuration set generated on 21-May-2021 09:10:54
% MATLAB version: 9.6.0.1472908 (R2019a) Update 9
%cs = Simulink.ConfigSet;
open(model_name);%change, model_name即为想将配置导入到其中的模型名称
cs = getActiveConfigSet(model_name);%change
% Original configuration set version: 19.0.0
if cs.versionCompare('19.0.0') < 0
error('Simulink:MFileVersionViolation', 'The version of the target configuration set is older than the original configuration set.');
end
调用方法:
ActiveConfig('untitled');
以上即可将配置导入到“untitled.slx”中
cs.set_param('UtilityFuncGeneration', 'Shared location'); % Shared code placement
可以把一些查表接口单独生成文件,这些文件会放到slprj文件夹。
可以限定一些局部变量的名称。