Filter löschen
Filter löschen

With sltest.TestCase, how can I execute one time step of my model at a time?

2 Ansichten (letzte 30 Tage)
Taylor
Taylor am 23 Jun. 2023
Kommentiert: Taylor am 23 Aug. 2023
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?

Antworten (1)

Anshuman
Anshuman am 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!
  1 Kommentar
Taylor
Taylor am 23 Aug. 2023
Ah. Dang. I was hoping for a method to execute a single timestep at a time for various reasons. I'll stick with the sim command for now I guess.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Test Execution finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by