Accessing Simulink Test Signals by Name
20 views (last 30 days)
Show older comments
I am trying to create custom Criteria for a Simulation Test. The Test Result depends on the final value of some signals, as such I am trying to access said signals in the Custom Criteria Function.
Entering this code into the box...
outobj = TestResult.getOutputRuns;
x_pos = outobj.getSignalByIndex(1)
sltest_simout.get('x_vec_no_airdrag:1(1)')
sltest_simout.get('x_vec_no_airdrag')
...yields the following Output in the MATLAB Command Window.
x_pos =
Signal with properties:
ID: 49573
RunID: 49576
Name: 'x_vec_no_airdrag:1(1)'
Units: ''
DataType: 'double'
Complexity: "real"
ComplexFormat: "real-imaginary"
SampleTime: 'Continuous'
Model: 'Flugbahn_Ideal_Harness'
BlockPath: 'Flugbahn_Ideal_Harness/x_vec_no_airdrag'
FullBlockPath: 'Flugbahn_Ideal_Harness/x_vec_no_airdrag'
PortIndex: 1
Dimensions: 2
Channel: 1
Checked: 0
LineColor: [0.7180 0.2750 1]
LineDashed: '-'
InterpMethod: 'linear'
AbsTol: 0
RelTol: 0
TimeTol: 0
SyncMethod: 'union'
Values: [1×1 timeseries]
RootSource: ''
TimeSource: ''
DataSource: ''
ans =
[]
ans =
[]
Using the get Function for this purpose is explained here: https://de.mathworks.com/help/sltest/ug/define-custom-criteria-for-test-case-results.html
However, the values returned by sltest_simout.get() are empty even though I am referring to them with their correct name. What am I doing wrong?
0 Comments
Answers (1)
Shishir Dwivedi
on 27 Dec 2019
Hello Danish,
You might need to log the signal of interest to get the desired output. With prerequisite that "Signal logging" is on the model (Configuration parameters) and have provided some name to Signal logging variable (say, logsout).
log the signal "x_vec_no_airdrag" & use following command. This would give you test results in "Simulink.SimulationData.Signal" associated with "x_vec_no_airdrag"
outobj = TestResult.getOutputRuns;
x_pos = outobj.getSignalByIndex(1);
sigD = sltest_simout.get('logsout').get(x_pos.Name)
-Shishir.
1 Comment
Lorenzo Zustovich
on 27 Jan 2021
Hi, I am interested in this topic.
Following what @Shishir Dwivedi suggested, how can the siganl be plot in the "Custom Criteria" pane in the Test Manager?
I used the following sintax, but does not work:
outobj = TestResult.getOutputRuns;
x_pos = outobj.getSignalByIndex(1);
sigD = sltest_simout.get('logsout').get(x_pos.Name);
% Plot WD feed cmd
plot(sigD);
grid on;
Best regards
See Also
Categories
Find more on Outputs 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!