Main Content

Simulink.playback.Signal

Container for signals to add to Playback block

Since R2024a

    Description

    The software uses Simulink.playback.Signal objects to store information about signals added to the Playback block.

    To programmatically add data to the Playback block, create a Simulink.playback.Signal object containing the signals you want to add. Then, use the set_param function to set the Simulink.playback.Signal object as the value of the Signals parameter of the Playback block.

    Creation

    Use the Simulink.playback.createSignals to create a Simulink.playback.Signal object.

    The input required for the Simulink.playback.createSignals function depends on the source of the data. To create a Simulink.playback.Signal object that contains information about signals from these sources, specify the necessary information:

    SourceRequired Input
    WorkspaceSpecify the source and the variable names.
    FileSpecify the filename.
    Simulation Data InspectorSpecify the source and either the run ID or the name of the Simulation Data Inspector run that contains the signals.

    Optionally, you can also provide inputs to specify whether to reference the signals in the source or save a copy of the signals in the model, and whether to assign ports automatically or not assign ports.

    Properties

    expand all

    Source of data, specified as:

    • "workspace" — Source signal data from the workspace.

    • "sdi — Source data from the Simulation Data Inspector.

    • file name — Source data from a file.

    For more information about workspace variables and file formats supported by the Playback block, see Import Data from Workspace or File into Simulation Data Inspector.

    Example: "myData.mat"

    Whether signal in Playback block is referenced in source or saved in model, returned as one of these values:

    • 1 (true) — The data is referenced in the source linking the signal added to the Playback block to the variable or file that contains the signal data. If the data in the source variable or file changes, that change is reflected in the data added to the Playback block. When linking data, only metadata is stored on the block for each signal.

    • 0 (false) — A copy of the signal data is saved in the model. Changes made to the original data source variable or file are not reflected in the data added to the Playback block.

    Adding data to the Playback block from the Simulation Data Inspector always saves a copy of the data in the model.

    Signal name, returned as a character vector or string.

    When you add a signal to the Playback block from the workspace, the Name property displays the workspace variable name by default.

    Example: 'Sine'

    Simulation Data Inspector run name, returned as a character vector or string.

    When you add a signal to the Playback block from the workspace or a file, the RunName property is empty by default.

    Example: 'Run 1: vdp'

    Port index of signal in Playback block, returned as a character vector, 'auto', or 'none'.

    When you use the get_param function to return a Simulink.playback.Signal object for a signal added to the Playback block, the PortIndex property returns a character vector containing the numerical port index of the signal. When the signal is a multidimensional signal that has been expanded into channels, the PortIndex property returns a character vector containing a vector with the index for each channel. The PortIndex property returns '0' when the signal is not assigned to a port.

    When you use the Simulink.playback.createSignals function to create a Simulink.playback.Signal object to add to the Playback block, the PortIndex property returns 'auto' if the Playback block assigns ports automatically and 'none' if the Playback block does not assign ports to the added signals.

    Example: '2'

    Examples

    collapse all

    The PlaybackRecord model contains an empty Playback block connected to a Record block. Using the set_param function, you can programmatically add new signals to the Playback block by setting the value of the Signals parameter to a Simulink.playback.Signal object that contains information about the signals you want to add to the block. Once you add data, the Playback block loads external data into the model during simulation. The Record block logs output data from the Playback block.

    mdl = "PlaybackRecord";
    open_system(mdl)

    The PlaybackRecord model

    Create two timeseries objects in the workspace. The timeseries object ts1 stores data for a sine wave and has the signal name Sine. The timeseries object ts2 stores data for a cosine wave and has the signal name Cosine.

    time = 0:0.1:10;
    ts1 = timeseries(sin(time),"Name","Sine");
    ts2 = timeseries(cos(time),"Name","Cosine");

    Use the Simulink.playback.createSignals function to create a Simulink.playback.Signal object that contains the workspace variables ts1 and ts2.

    wkspSigs = Simulink.playback.createSignals("workspace","Variables",["ts1","ts2"]);

    To add the workspace data to the Playback block, use the set_param function to apply the Simulink.playback.Signal object to the Signals parameter of the Playback block.

    set_param("PlaybackRecord/Playback","Signals",wkspSigs)

    In the model, connect the second port of the Playback block to the Record block. The Playback block displays the names of the added signals. To load the workspace data from the Playback block into your model, run the simulation.

    The PlaybackRecord model showing the Cosine and Sine signals added to the block

    To get information about the signals added to the Playback block, use the get_param function. For example, get information about the Simulink.playback.Signal object that contains data for the Sine signal.

    sigsInfo = get_param("PlaybackRecord/Playback","Signals");
    sineSigInfo = sigsInfo(2)
    sineSigInfo = 
      Signal with properties:
    
           Source: 'workspace'
         IsLinked: 1
             Name: 'ts1'
          RunName: ''
        PortIndex: '2'
    
    

    Version History

    Introduced in R2024a