This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Log Signals in For Each Subsystems

The approach you use to log data for a signal in a For Each subsystem depends on whether the signal is a:

  • Nonbus signal — Log directly in a For Each subsystem

  • A bus or array of buses signal — Use one of these approaches:

    • Use a Bus Selector block to select the signals you want to log and mark those signals for signal logging. This approach works well for many models.

    • Attach the signal to an Outport block and log the signal outside of the For Each subsystem. Use this approach when you want to log a whole bus signal, and that bus signal includes many bus element signals.


You cannot log bus signals directly in a For Each subsystem.

You cannot log a signal inside a referenced model that is inside a For Each subsystem if either of these conditions exists:

  • The For Each subsystem is in a model simulating in rapid accelerator mode.

  • The For Each subsystem itself is in a model referenced by a Model block in accelerator mode.

The data for each logged signal in a For Each subsystem is saved in a separate Dataset element as a Simulink.SimulationData.Signal object. The format of the logged signal data depends on how you set the Dataset signal format configuration parameter:

  • If the setting is timeseries, then each signal object contains an array of MATLAB® timeseries objects. The array keeps the data from different For Each iteration separate.

  • If the setting is timetable, then each signal object contains a cell array of MATLAB timetable objects. The dimensions of this array match the number of For Each iterations. For example, if the For Each subsystem has three iterations, then the logged data has a 3x1 array of timeseries or timetable objects. For nested For Each subsystems, each layer of nesting adds another dimension to the logged data.

Log Signal in Nested For Each Subsystem

This example logs a signal in a nested For Each subsystem.

Open the ex_loginsideforeach_nested model.


In the Simulink® Editor, open the For Each Subsystem1 block, and inside that subsystem, open the For Each Subsystem2 block.

Simulate the model and examine the signal logging data for the first iteration of the top subsystem and the third iteration of the bottom subsystem. The 2x3 timeseries results from two iterations at the first For Each level and three iterations at the second (nested) level

ans = 

  Package: Simulink.SimulationData

  struct with fields:

              Name: 'nestedDelay'
    PropagatedName: ''
         BlockPath: [1×1 Simulink.SimulationData.BlockPath]
          PortType: 'outport'
         PortIndex: 1
            Values: [2×3 timeseries]

Return the values of the nestedDelay object.


  Common Properties:
            Name: 'nestedDelay'
            Time: [5x1 double]
        TimeInfo: [1x1 tsdata.timemetadata]
            Data: [1x1x5 double]
        DataInfo: [1x1 tsdata.datametadata]

Log Bus Signals in For Each Subsystem

This example logs a two bus signal in a For Each subsystem. For one bus signal, you use a Bus Selector block and then log each selected signal. For the other bus signal, you use Outport blocks and log outside of the For Each subsystem.

Open the ex_for_each_log_bus model.


In the Simulink Editor, open the For Each Subsystem block.

To log the signals in the limits bus signal, the signal is branched to a Bus Selector block, and each of the bus element signals is marked for signal logging.

To log the whole COUNTERBUS signal, the bus signal is connected to an Outport block. The output signal from the For Each subsystem is marked for signal logging. To have the bus signal cross the subsystem boundary, the Bus Creator block that creates the COUNTERBUS signal has the Output data type parameter set to Bus: COUNTERBUS and Output as nonvirtual bus check box selected.

Simulate the model and examine the signal logging output. Focus on one of the bus element signals logged inside the For Each subsystem and on the bus signal logged outside of the For Each subsystem.

Simulink.SimulationData.Dataset 'logsout' with 3 elements

                         Name                      BlockPath                                
                         ________________________  ________________________________________ 
    1  [1x1 Signal]      OutsideForEach            ex_for_each_log_bus/For Each Subsystem  
    2  [1x1 Signal]      <lower_saturation_limit>  ...g_bus/For Each Subsystem/Bus Selector
    3  [1x1 Signal]      <upper_saturation_limit>  ...g_bus/For Each Subsystem/Bus Selector

  - Use braces { } to access, modify, or add elements using index.

Return the values of the lower_saturation_limit object.

3×1 timeseries array with properties:


Return the values of the OutsideForEach object.

 ans = 

  3×1 struct array with fields:


If the Dataset signal format is timetable, then the output is a cell array of timetable objects. For example:

out = sim('ex_for_each_log_bus','DatasetSignalFormat','timetable');
ans =
 3x1 cell array

  {11x1 timetable}
  {11x1 timetable}
  {11x1 timetable}

See Also



Related Topics