Main Content

Simulink.analytics.getMetrics

Get descriptive statistics for data stored in Simulink.sdi.Signal objects

Since R2026a

    Description

    signalStats = Simulink.analytics.getMetrics(signalID) returns descriptive statistics for signal data stored in the Simulink.sdi.Signal object specified by the signal identifier signalID.

    example

    signalStats = Simulink.analytics.getMetrics(signalID,startTime) returns descriptive statistics in the time interval between startTime and the end of simulation.

    signalStats = Simulink.analytics.getMetrics(signalID,startTime,endTime) returns descriptive statistics in the time interval specified by startTime and endTime, inclusive.

    Examples

    collapse all

    Suppose you log a signal generated from a Random Number block to the Simulation Data Inspector. To get descriptive statistics for signal, use the Simulink.analytics.getMetrics function.

    A signal generated from a Random Number block plotted on a time plot in the Simulation Data Inspector.

    Get the signal ID for the signal named randSig.

    runObj = Simulink.sdi.Run.getLatest;
    sigID = getSignalIDsByName(runObj,"randSig");

    Use the Simulink.analytics.getMetrics function to return descriptive statistics for the signal.

    sigStats = Simulink.analytics.getMetrics(sigID)
    sigStats = 
    
      struct with fields:
    
               min: -2.4828
               max: 2.0185
        peakToPeak: 4.5013
              mean: 0.0708
            median: 0.1479
               std: 0.9490
               rms: 0.9470

    To find the descriptive statistics near the end of the simulation, specify the starting time. For example, to find the descriptive statistics for the last two seconds of the 10 second simulation, specify startTime as 8.

    sigStatsEnd = Simulink.analytics.getMetrics(sigID,8)
    sigStatsEnd = 
    
      struct with fields:
    
               min: -2.4828
               max: 1.7524
        peakToPeak: 4.2352
              mean: 0.1382
            median: 0.3946
               std: 0.9735
               rms: 0.9600

    To find the descriptive statistics in a specific interval, specify the start and end time of the interval. For example, find the descriptive statistics in the interval between 2 seconds and 4 seconds.

    sigStatsInterval = Simulink.analytics.getMetrics(sigID,2,4)
    sigStatsInterval = 
    
      struct with fields:
    
               min: -2.3775
               max: 1.6065
        peakToPeak: 3.9840
              mean: 0.0684
            median: 0.3180
               std: 0.9016
               rms: 0.8825

    Suppose you log a signal generated from a Random Number block using a Record block. To get descriptive statistics for signal, use the Simulink.analytics.getMetrics function.

    A signal generated from a Random Number block logged using the Record block.

    Get the signal ID for signal named randSig in the Record block.

    recordSigIds = get_param("myModel/Record","signalIDs");
    sigID = recordSigIds(1);

    Use the Simulink.analytics.getMetrics function to return descriptive statistics for the signal.

    recordSigStats = Simulink.analytics.getMetrics(sigID)
    recordSigStats = 
    
      struct with fields:
    
               min: -2.4828
               max: 2.0185
        peakToPeak: 4.5013
              mean: 0.0708
            median: 0.1479
               std: 0.9490
               rms: 0.9470

    Suppose you add a signal generated from a Random Number block to a Playback block. To get descriptive statistics for signal, use the Simulink.analytics.getMetrics function.

    A signal generated from a Random Number block added to the Playback block.

    Get the signal ID for signal named randSig in the Playback block.

    playbackSigIds = get_param("myModel/Playback","signalIDs");
    sigID = playbackSigIds(1);

    Use the Simulink.analytics.getMetrics function to return descriptive statistics for the signal.

    playbackSigStats = Simulink.analytics.getMetrics(sigID)
    playbackSigStats = 
    
      struct with fields:
    
               min: -2.4828
               max: 2.0185
        peakToPeak: 4.5013
              mean: 0.0708
            median: 0.1479
               std: 0.9490
               rms: 0.9470

    Input Arguments

    collapse all

    Unique Simulation Data Inspector signal identifier, specified as a positive integer. The software creates a Simulink.sdi.Signal object for each signal you log in a model simulation or import into the Simulation Data Inspector. You can get the signal ID for a signal using getAllSignalIDs, getSignalIDByIndex, or getSignalIDsByName.

    When the signalID identifies a complex signal, the Simulink.analytics.getMetrics function finds the descriptive statistics for the real part of the signal.

    To get descriptive statistics for multidimensional signal data, use the expand to convert the data into channels.

    Start time, specified as a nonnegative scalar less than endTime. This time specifies the beginning of the time interval in which to find a minimum value.

    End time, specified as a nonnegative scalar greater than startTime and less than the total simulation time. This time specifies the end of the time interval in which to find a minimum value.

    Output Arguments

    collapse all

    Descriptive statistics for signal, returned as a structure that contains these fields:

    • min — Minimum data value

    • max — Maximum data value

    • peakToPeak — Range of data values

    • mean — Mean of signal data values

    • median — Median of signal data values

    • std — Standard deviation of signal data values

    • rms — Root mean square value of signal data

    Version History

    Introduced in R2026a