isValidSignalID

Check whether signal ID corresponds to signal in Simulink.sdi.Run object

Description

example

isValid = isValidSignalID(runObj,sigID) returns the logical indication isValid of whether the signal ID sigID corresponds to a signal in the Simulink.sdi.Run object runObj.

Examples

collapse all

This example uses the slexAircraftExample model to demonstrate how to compare the input and output signals of the control system.

Configure and Simulate the Model

The slexAircraftExample model does not log data. Load the model and mark the input and output signals for logging.

load_system('slexAircraftExample')
Simulink.sdi.markSignalForStreaming('slexAircraftExample/Pilot',1,'on')
Simulink.sdi.markSignalForStreaming('slexAircraftExample/Aircraft Dynamics Model',4,'on')

Simulate the model. The data for the logged signals logs to the Simulation Data Inspector and to the workspace.

out = sim('slexAircraftExample');

Access Simulation Data

Use the Simulation Data Inspector programmatic interface to access the data. The Simulink.sdi.Run.getLatest function returns the most recently created run in the Simulation Data Inspector repository. Use the getSignalIDByIndex function to access the signal IDs for the logged signals.

aircraftRun = Simulink.sdi.Run.getLatest;

signalID1 = getSignalIDByIndex(aircraftRun,1);
signalID2 = getSignalIDByIndex(aircraftRun,2);

Specify Tolerance Values

You can specify tolerance values to use in the comparison as a property in the logged Simulink.sdi.Signal object. Use the Simulink.sdi.getSignal function to access the Signal object using the signal ID.

signal1 = Simulink.sdi.getSignal(signalID1);
signal1.AbsTol = 0.1;

Compare Signals

Use the Simulink.sdi.compareSignals function to compare the input and output signals. This example uses the isValidSignalID function to verify that both signal IDs are still valid before calling the Simulink.sdi.compareSignals function. A signal ID becomes invalid when the signal is deleted from the Simulation Data Inspector. After the comparison, check the status in the Simulink.sdi.DiffSignalResult object.

if (isValidSignalID(aircraftRun,signalID1) && isValidSignalID(aircraftRun,signalID2))
    sigDiff = Simulink.sdi.compareSignals(signalID1,signalID2);

    match = sigDiff.Status
end
match = 
OutOfTolerance

The comparison result is out of tolerance. You can use the Simulink.sdi.view function to inspect and analyze the comparison results.

Input Arguments

collapse all

Run in the Simulation Data Inspector, specified as a Simulink.sdi.Run object.

Unique numeric signal identifier, specified as an integer. The Simulation Data Inspector assigns a signal ID to each signal when a run is created. You can get the signal ID for a signal using one of these functions:

Output Arguments

collapse all

Signal validity, returned as a logical 1 or 0.

  • 1 — The specified signal ID corresponds to a signal in the specified run.

  • 0 — The specified signal ID does not correspond to a signal in the specified run.

Introduced in R2012b