How do I automatically export Simulink Test Data from the test manager with a script
显示 更早的评论
I would like to run tests in the testmanger and export the model outputs so I can parse it and update my baseline spreadsheet with data.
I have tried the script below. but the result of 'getTestCaseResults(tsr)' function does not hold the output data. The only way I can do it right now is righ clicking on the test resulut in the manager and clicking export data.
clear;
sltest.testmanager.clear;
% Define the name of the Simulink model and the test file
modelName = 'brake_control.slx'; % Replace with your model name
testFileName = 'brake_control.mldatx'; % Replace with your test file name
% Load the model
load_system(modelName);
testFile = sltest.testmanager.load(testFileName);
resultsobj = sltest.testmanager.run;
tfr = getTestFileResults(resultsobj);
tsr = getTestSuiteResults(tfr);
tcr = getTestCaseResults(tsr);
回答(1 个)
The signals under the Sim Output section in the Test Manager can be accessed as a Dataset and utilized as needed. Here's a guide on how to achieve this using an example from the documentation, which can be found here:
After running the test file, the Sim Output signals should appear in the test results.

To get the handle to the Sim Output section, which is a Simulink.sdi.Run object, execute the following command:
resultSet = sltest.testmanager.getResultSets;
tfr = resultSet.getTestFileResults;
tsr = tfr.getTestSuiteResults;
tcr = tsr.getTestCaseResults;
simOut = tcr.getOutputRuns

The export method of the simOut object can then be used to export the signal to the base workspace or a file. For more information, refer to the following link:
类别
在 帮助中心 和 File Exchange 中查找有关 Test Scripts 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!