How to call the Simulink Test results inside the ForEach module?

Hello, I want to use the test results from Simulink Test to perform custom evaluation criteria. My model uses a For Each subsystem externally to calculate the maximum and minimum SOC of individual cells within a battery pack in parallel. The battery SOC is an output of the model, and for each battery's SOC, I can record and call it using the code below:
soc = test.sltest_simout.get('logsout').get('soc').Values.Data;
soc_max = soc(:,1);
soc_min = soc(:,2);
However, I also want to record the terminal voltage estimation error of a battery inside the For Each subsystem. This value is internal to the For Each subsystem and is not output to the outside of the model. If I try to call the test data in the same way as above, I get an 'index exceeds 1' error:
v_error = test.sltest_simout.get('logsout').get('v_error').Values.Data;
v_max_error = v_error(:,1);
v_max_error = v_error(:,2);
In Simulink Test, there are also two output results, but it seems that it calculates them channel by channel. So, how should I call the v_error test results?

 Accepted Answer

Hi @Ke,
I understand you are using a For Each subsystem for battery cell calculations but are encountering an 'index exceeds 1' error when accessing the internal v_error signal. This occurs because signals logged inside a For Each block use a different data structure than the external SOC matrix you have successfully retrieved.
The signals logged inside a For Each subsystem are stored as an array of timeseries objects, rather than a single timeseries object with multiple columns. So, you must index into .Values field before accessing .Data field as shown below:
v_error_sig = test.sltest_simout.get('logsout').get('v_error');
v_max_error_1 = v_error_sig.Values(1).Data;
v_max_error_2 = v_error_sig.Values(2).Data;
Here is a useful Documentation regarding Log Signals in For-Each Subsystems (run it in MATLAB command window):
>> web(fullfile(docroot, 'simulink/ug/log-signals-in-for-each-subsystems-1.html'))
Hope this is helpful.

3 Comments

Thank you very much for your response. This solved my problem with obtaining the results. Additionally, when I was customizing the evaluation criteria, I used fprintf to display some information, but the relevant information did not appear when I called my evaluation criteria. What could be the reason for this?
@Ke, I am glad to hear that the For Each indexing solution worked for you!
The reason your text is not appearing in the MATLAB Command Window is that Simulink Test redirects standard output (like fprintf) to the Test Manager's internal results log. This ensures that if you run hundreds of tests, the Command Window is not flooded with text.
Hello, but I didn't see any relevant print information in the Simulink Test logs either. How can I view this information?

Sign in to comment.

More Answers (0)

Products

Release

R2020b

Asked:

Ke
on 15 Jan 2026

Commented:

Ke
on 21 Jan 2026

Community Treasure Hunt

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

Start Hunting!