Logging Signals

About Signal Logging

Logging signals refers to the process of saving signal values to the MATLAB® workspace during simulation for later retrieval and postprocessing. Simulink® allows you to log a signal by

All of these methods allow you to specify the names of the workspace variables used to save signal data and to limit the amount of data logged for a particular signal.

See Simulink® Reference for the To Workspace and Outport blocks for information on using these blocks to log signal data. See the documentation of the sim command for some data logging capabilities that are available only for programmatic simulation.

Signal Logging Limitations

Simulink does not support signal logging for the following types of signals:

Multidimensional signals are supported.

Bus hierarchy is supported. The hierarchy of a bus signal is preserved in the logsout object. See Using Composite Signals for details about muxes and buses.

Enabling Signal Logging

To enable signal logging for a signal, select the Log signal data option on the signal's Signal Properties dialog box (see Signal Properties Dialog Box).

Globally Enabling and Disabling Signal Logging

You can globally enable or disable signal logging for a model by checking or unchecking the Signal logging option on the Data Import/Export pane of the Configuration Parameters dialog box (see Signal logging ). Simulink logs signals only if this option is checked. If the option is not checked, Simulink ignores the signal logging settings for individual signals.

Enabling Signal Logging Programmatically

You can enable signal logging programmatically for selected blocks with the outport DataLogging property. You can set this property using the set_param command. For example:

  1. At the MATLAB Command Window, open a model. Type

    vdp
  2. Select a block in that model. For example, select the Mux block.

  3. Get the port handles of the selected block.

    get_param(gcb,'PortHandles')
  4. Enable signal logging for the desired outport port.

    set_param(ans.Outport(1),'DataLogging','on')

    The logged signal indicator ( ) appears.

Specifying a Logging Name

You can assign a name, called the logging name, to the object used to log data for a signal during simulation.

To specify a log name for a signal, select Custom from the Logging name list on the signal's Signal Properties dialog box and enter the custom name in the adjacent text field.

If you do not specify a custom logging name, Simulink uses the signal name, or if there is no name, Simulink generates a default name that is composed of the block name and port number. For example, if the block name is MyBlock and the signal being logged is the first output of this block, Simulink generates the following name: SL_MyBlock1.

Limiting the Data Logged for a Signal

The Data panel of the Signal Properties dialog box lets you limit the amount of data logged for a signal. For example, you can specify the maximum amount of data to be logged for a signal or a decimation factor that causes Simulink to skip a specified number of time steps before logging a signal value. See Data for more information.

Logging Referenced Model Signals

You can log any signal that is defined as a test point in a referenced model. For information about test points, see Designating a Signal as a Test Point. For information about referenced models, see Referencing a Model.

To log test pointed signals in referenced models, select the Model block and then select Log referenced signals from the model editor's Edit menu or from the block's context menu.

The Model Reference Signal Logging dialog box appears.

The dialog box contains the following panes and controls.

Model Hierarchy

This pane displays the contents of the referenced model as a tree control with expandable nodes. The top-level node represents the referenced model. Expanding this node displays the subsystems that the referenced model contains and any models that it itself references. Expanding a subsystem node displays the subsystems that it contains and the models that it references.

Refresh Button

Refreshes the dialog box to reflect changes in the model hierarchy.

Signals

This pane displays the test points of the model or subsystem selected in the Model Hierarchy pane (see Working with Test Points). Check the check box next to a test point's name to specify that it should be logged.

Log signals as specified by the referenced model

Checking this check box causes Simulink to log the signals that the referenced model specifies should be logged.

Signal Properties

This pane is enabled if Log signals as specified by the referenced model is not selected. In this case, the controls on this pane allow you to specify the signal logging properties of the signal selected in the Signals pane. The values that you specify override for this instance of the referenced model those specified by the model itself. The controls correspond to the controls of the same name on the Signal Properties dialog box. See Signal Properties Dialog Box for information on how to use them.

Viewing Logged Signal Data

To view logged signal data, either check the Inspect signals when simulation is stopped/paused in the Data Import/Export pane of the Configuration Parameters dialog box or select Tools > Inspect Logged Signals from the model editor's menu bar. The first method causes Simulink to display logged signals in the MATLAB Time Series Tools viewer (see in the online MATLAB documentation) whenever a simulation ends or you pause a simulation. The second method causes Simulink to display the data immediately.

Accessing Logged Signal Data

Simulink saves signal data that it logs during simulation in a Simulink data object of type Simulink.ModelDataLogs that resides in the MATLAB workspace. The name of the object's handle is logsout by default. The Data Import/Export configuration pane (see Data Import/Export Pane) allows you to specify another name for this object. See Simulink.ModelDataLogs in the online Simulink reference for information on extracting signal data from this object.

The signal logs for particular model elements are contained in the objects in the following table. The Simulink.ModelDataLogs object is the container for these objects.

Modeling ElementSignal Data Object
Signal in this modelSimulink.Timeseries
Model referenced by this modelSimulink.ModelDataLogs
SubsystemSimulink.SubsysDataLogs
Bus, mux, vector concatenateSimulink.TsArray
ScopeSimulink.ScopeDataLogs

Example: Logging Signal Data in the F14 Model

Enabling signal logging on a signal-by-signal basis allows you to store signal data without modifying the structure of the Simulink diagram. For example, use the following steps to log and access the signal data for the vertical velocity signal w in the F14 model.

  1. Open the F14 model by typing f14 at the MATLAB command prompt.

  2. Right-click on the signal labeled w and select the Signal Properties menu.

  3. In the Signal Properties dialog box that opens, check the Log signal data option. Notice that the Test point option automatically becomes checked and the logging name initializes to the signal's name.

  4. Click the OK button on the Signal Properties dialog box. The 'blue antenna' icon appears on the signal labeled w, indicating that this signal will be logged during simulation.

  5. Ensure that the Signal logging option on the Data Import/Export pane of the Configuration Parameters dialog box is checked and that the logging name is set to the default variable logsout.

  6. Run the F14 simulation. The logged signal data is stored in a Simulink.ModelDataLogs object named logsout in the MATLAB workspace. Typing logsout at the MATLAB command prompt displays the following

    logsout =
     
    Simulink.ModelDataLogs (f14):
      Name                   Elements  Simulink Class
    
      w                         1      Timeseries
  7. Type logsout.w to view the information stored for the signal w.

    logsout.w
              Name: 'w'
         BlockPath: 'f14/Aircraft Dynamics Model'
         PortIndex: 1
        SignalName: 'w'
        ParentName: 'w'
          TimeInfo: [1x1 Simulink.TimeInfo]
              Time: [1353x1 double]
              Data: [1353x1 double]
  8. To inspect the signal using the MATLAB Time Series Tools, select Inspect Logged Signals from the f14 model editor's Tools menu (see in the online MATLAB documentation).

Handling Spaces and Newlines in Logged Signal Names

Named signals that are used for signal logging but do not have an associated Simulink.Signal object can have names that include space and newline characters, as described in Naming Signals. Such names can improve the readability of a block diagram, but referencing them requires require special techniques when they appear in a data log. These techniques allow the MATLAB parser to process the names even though spaces and newlines are not legal in MATLAB identifiers.

Space and newline characters can also appear in a data log when an unnamed logged signal originates in a block whose name contains any spaces or newlines. The Simulink software constructs a name for the signal based on the block name, and the constructed name inherits the characters that the block name contains; these characters then appear in the data log. This situation often arises, because many blocks have spaces in their default names. One way to avoid it is to name the logged signal, thus avoiding the default name.

The following model includes a signal whose name contains a space, a signal whose name contains a newline, and an unnamed signal that originates in a block whose name contains a newline:

If you execute this model with data logging enabled in the Data Import/Export pane, accepting the default logging object name logsout, and then type logsout in the MATLAB Command Window, MATLAB displays the following data log:

logsout =
 
Simulink.ModelDataLogs (model_name):
  Name                   Elements  Simulink Class

  ('x y')                   1      Timeseries
  ('a
b')                   1      Timeseries
  ('SL_Sine
Wave1')         1      Timeseries

You cannot access any of the Timeseries objects in this log using TAB name completion, or by typing the name to MATLAB, because the space or newline in each name appears to the MATLAB parser as a separator between identifiers. For example:

>> logsout.x y

??? logsout.x y
              |
Error: Unexpected MATLAB expression.

To reference a Timeseries object whose name contains a space, single-quote the element containing the space:

>> logsout.('x y')

          Name: 'x y'
     BlockPath: 'model_name/Sine'
     PortIndex: 1
    SignalName: 'x y'
    ParentName: 'x y'
      TimeInfo: [1x1 Simulink.TimeInfo]
          Time: [51x1 double]
          Data: [51x1 double]

To reference a Timeseries object whose name contains a newline, concatenate to construct the element containing the newline:

>> cr=sprintf('\n')
>> logsout.(['a' cr 'b'])

The same technique works when the newline derives from a block name used to generate a name for an unnamed signal:

>> logsout.(['SL_Sine' cr 'Wave1'])

For names with multiple spaces, newlines, or both, repeat and combine the two techniques as needed to specify the intended name to MATLAB. No analogous techniques exist for TAB name completion, which never works with names that contain space or newline characters.

Extracting Partial Data from a Running Simulation

Before a simulation ends, you can extract and write the currently logged signal data (from Simulink.ModelDataLogs) with the set_param WriteDataLogs command. The currently logged signal is the partial data logged between when the simulation started and when you request an extraction of the signal data. If you use this command during the simulation, Simulink writes the current logging variable values to the MATLAB workspace. If you use this command at the end of the simulation, Simulink writes the values from the last simulation to the MATLAB workspace.

To use this command, type the following at the MATLAB Command Window.

set_param(bdroot,'SimulationCommand','WriteDataLogs')
  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS