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

5 ビュー (過去 30 日間)
Taylor
Taylor 2023 年 6 月 23 日
コメント済み: Taylor 2023 年 8 月 23 日
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?

回答 (1 件)

Anshuman
Anshuman 2023 年 8 月 2 日
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 件のコメント
Taylor
Taylor 2023 年 8 月 23 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTest Scripts についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by