With sltest.TestCase, how can I execute one time step of my model at a time?
2 views (last 30 days)
Show older comments
With sltest.TestCase, how can I execute one time step of my model at a time and access the output from the current time step?
For example, if I had a simulink model called "testSim.slx", I would like to be able to create a simulation object (or something similar), initialize the object, then call something like [outputs, states] = testSimObject.step(inputs).
Is something like this possible without generating code?
0 Comments
Answers (1)
Anshuman
on 2 Aug 2023
Hi Taylor, the sltest.TestCase class is primarily designed for creating and managing test cases, which involve running simulations based on test inputs and verifying the expected outputs against the actual outputs. The TestCase class provides methods to set up the test environment, define inputs, and run simulations.
To access the output from the current time step during a simulation, you can use the 'sim' method provided by the sltest.TestCase class. Here's an example of how you can use it:
% Create a test case
testCase = sltest.TestCase('testSim');
% Set the simulation time step
testCase.TestSimulationSettings.StopTime = 1; % Set the desired stop time for one time step
% Run the simulation
simOut = sim(modelName);
% Access the output from the current time step
outputs = simOut.logsout.get('OutputSignal').Values(end); % Replace 'OutputSignal' with the name of your output signal
% Access the states from the current time step
states = simOut.logsout.get('StateSignal').Values(end); % Replace 'StateSignal' with the name of your state signal
In this example, the 'sim' method is used to run the simulation defined by the test case. The 'simOut' variable contains the simulation output, which includes the logged signals. By accessing the 'Values' property of the logged signals, you can obtain the output and state values at the last time step. Refer to this article sim for more details.
Hope it helps!
See Also
Categories
Find more on Test Scripts in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!