Main Content

findSignal

Find index of signals in Signals property vector

    Description

    example

    sigIdx = findSignal(mdlInfo,blkPath) creates a vector of numeric indices corresponding to the Signals vector of the model logging override settings object mdlInfo for the signals specified by the block path blkPath.

    • To find a single instance of a signal within a referenced model, use a Simulink.BlockPath object or a cell array with a full path.

    • To find all instances of a signal within a referenced model, use a character vector with the relative path of the signal within the referenced model.

    • To find a logged chart signal within a Stateflow® chart, use a Simulink.BlockPath object and set the SubPath property to the name of the Stateflow chart signal.

    sigIdx = findSignal(mdlInfo,blkPath, portIdx) finds the indices of the output signal for the specified port.

    Do not use the portIdx argument for Stateflow chart signals. For an example that uses the findSignal function with a Stateflow chart, see Override Logging Properties with the Command-Line API (Stateflow).

    Examples

    collapse all

    You can use the findSignal function to find the index of a signal in a model logging override object. This example uses the model sldemo_mdlref_bus which logs four signals. Three of the logged signals are located in the top model. The fourth signal is located in the referenced model sldemo_mdlref_counter_bus.

    mdl = 'sldemo_mdlref_bus';
    open_system(mdl)

    Create a model logging override object with override settings for each logged signal in model.

    mdlInfo = Simulink.SimulationData.ModelLoggingInfo.createFromModel(mdl)
    mdlInfo = 
      ModelLoggingInfo with properties:
    
                         Model: 'sldemo_mdlref_bus'
                   LoggingMode: 'OverrideSignals'
        LogAsSpecifiedByModels: {}
                       Signals: [1x4 Simulink.SimulationData.SignalLoggingInfo]
    
    

    The INCREMENTBUS signal is located in the top model sldemo_mdlref_bus.slx. Using the block path to the IncrementBusCreator block, you can find the index of the INCREMENTBUS signal in the Signals property of the model logging override object mdlInfo.

    blkPath = 'sldemo_mdlref_bus/IncrementBusCreator';
    sigIdx = findSignal(mdlInfo,blkPath)
    sigIdx = 3
    

    You can also use the findSignal function to find a signal in a specific instance of a referenced model. For example, the INNERDATA signal is located in the referenced model CounterA. Using a block path to the Model block COUNTER in the sldemo_mdlref_counter_bus model, you can find the index of the INNERDATA signal in the Signals property of the model logging override object mdlInfo.

    blkPathRef = {'sldemo_mdlref_bus/CounterA','sldemo_mdlref_counter_bus/COUNTER'};
    sigIdxRef = findSignal(mdlInfo,blkPathRef)
    sigIdxRef = 4
    

    Input Arguments

    collapse all

    Model logging override object, specified as a Simulink.SimulationData.ModelLoggingInfo object.

    Source block to search, specified as a character vector, cell array of character vectors, or Simulink.Blockpath object.

    Index of the output port to search, specified as a positive integer.

    Version History

    Introduced in R2012b