Simulink-通过脚本自动创建一致性测试

#自动创建新、旧模型的一致性测试#

🔥 "为什么手工测试耗时易错?如何用脚本让Simulink模型验证效率提升10倍?"

本文揭秘军工级Simulink模型验证方案,手把手教你通过MATLAB脚本实现:
✅ 智能参数覆盖技术实现多工况自动遍历(附赠参数矩阵模板)
✅ 基线自动比对黑科技,0.1秒捕捉模型迭代中的异常行为
✅ 工业真实案例展示:某新能源车企如何用此法缩短测试周期从2周→4小时

💡 你会获得

  • 可直接复用的脚本代码库(含异常处理机制)

  • 与Jenkins/GitLab CI的无缝集成方案

  • 独家性能优化技巧(解决大型模型内存爆炸问题)

"这不是普通的自动化测试教程——而是让您团队告别加班的手把手生产力革命!"

% 自动创建testcase文件  要先运行ForCCode.m脚本
% sltest.testmanager.clear;
sltest.testmanager.view; % 打开模型测试管理器
addpath("Input");
Test_input_name=dir('Input\*.mat'); 
ModelName_old = 'old.slx';
ModelName_new = 'new.slx';

TestName = 'Test_Name';

for i=1:1:length(Test_input_name)
    InputMatName(i)=string(Test_input_name(i).name(1:end-4));
end

Test_file_creat=sltest.testmanager.TestFile(TestName);
Test_creat=createTestSuite(Test_file_creat,TestName);

%% 生成testCase
for i=1:1:length(Test_input_name)
    disp("正在生成第"+int2str(i)+"个Input对应的用例,共"+int2str(length(Test_input_name))+"个Input");
    Test_case_handl(i) = createTestCase(Test_creat,'equivalence',InputMatName(i)); % 生成等效性测试模板
    Test_case_name(i) = InputMatName(i);

     % 调用函数配置旧模型的仿真
    configureSimulation(Test_case_handl(i), ModelName_old, Test_input_name(i).name, 1);
    configureSimulation(Test_case_handl(i), ModelName_new, Test_input_name(i).name, 2);

    eq = captureEquivalenceCriteria(Test_case_handl(i)); % 捕获等效性准则
    ResultsObj = run(Test_case_handl(i)); % 运行对比性测试
end

function configureSimulation(testCaseHandle, modelName, inputDataName, simulationIndex)
    setProperty(testCaseHandle, 'Model', modelName, 'SimulationIndex', simulationIndex); % 设置模型
    setProperty(testCaseHandle, "StopSimAtLastTimePoint", true, 'SimulationIndex', simulationIndex); %打开最后一个时间步停止
    inputTemp = addInput(testCaseHandle, inputDataName, 'SimulationIndex', simulationIndex); % 向模型添加输入
    map(inputTemp,0); % 将输入映射
end

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Dr.Zeus

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值