Main Content

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 aBus Selectorblock 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 anOutportblock 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.

Note

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 aModelblock in accelerator mode.

The data for each logged signal in a For Each subsystem is saved in a separateDatasetelement as aSimulink.SimulationData.Signal对象。的格式记录信号数据求进步ds on how you set theDataset signal formatconfiguration parameter:

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

  • If the setting istimetable, then each signal object contains a cell array of MATLABtimetableobjects. 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 a3x1array oftimeseriesortimetableobjects. 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 theex_loginsideforeach_nestedmodel.

open_system(docpath(fullfile(docroot,'toolbox','simulink',...'examples','ex_loginsideforeach_nested.slx')))

In the Simulink®Editor, open theFor Each Subsystem1block, and inside that subsystem, open theFor Each Subsystem2block.

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. The2x3timeseriesresults from two iterations at the first For Each level and three iterations at the second (nested) level

sim('ex_loginsideforeach_nested'); logsout.get('nestedDelay')
ans = 金宝appSimulink.SimulationData.Signal包:一场link.SimulationData Properties: struct with fields: Name: 'nestedDelay' PropagatedName: '' BlockPath: [1×1 Simulink.SimulationData.BlockPath] PortType: 'outport' PortIndex: 1 Values: [2×3 timeseries]

Return the values of thenestedDelay对象。

logsout.get('nestedDelay').Values(1,3)
timeseries 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 aBus Selectorblock and then log each selected signal. For the other bus signal, you useOutportblocks and log outside of the For Each subsystem.

Open theex_for_each_log_busmodel.

open_system(docpath(fullfile(docroot,'toolbox','simulink',...'examples','ex_for_each_log_bus.slx')))

In the Simulink Editor, open theFor Each Subsystemblock.

To log the signals in thelimitsbus signal, the signal is branched to aBus Selectorblock, and each of the bus element signals is marked for signal logging.

To log the wholeCOUNTERBUSsignal, the bus signal is connected to anOutportblock. The output signal from the For Each subsystem is marked for signal logging. To have the bus signal cross the subsystem boundary, theBus Creatorblock that creates theCOUNTERBUSsignal has theOutput data typeparameter set toBus: COUNTERBUSandOutput as nonvirtual buscheck 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.

sim('ex_for_each_log_bus'); logsout
Simulink.SimulationData.Dataset 'logsout' with 3 elements Name BlockPath ________________________ ________________________________________ 1 [1x1 Signal] OutsideForEach ex_for_each_log_bus/For Each Subsystem 2 [1x1 Signal]  ...g_bus/For Each Subsystem/Bus Selector 3 [1x1 Signal]  ...g_bus/For Each Subsystem/Bus Selector - Use braces { } to access, modify, or add elements using index.

Return the values of thelower_saturation_limit对象。

logsout{2}.Values
3×1 timeseries array with properties: Events Name UserData Data DataInfo Time TimeInfo Quality QualityInfo IsTimeFirst TreatNaNasMissing Length

Return the values of theOutsideForEach对象。

logsout{1}.Values
ans = 3×1 struct array with fields: data limits

If theDatasetsignal format istimetable, then the output is a cell array oftimetableobjects. For example:

out = sim('ex_for_each_log_bus','DatasetSignalFormat','timetable'); out.logsout{2}.Values
ans = 3x1 cell array {11x1 timetable} {11x1 timetable} {11x1 timetable}

See Also

Blocks

Functions

Related Topics