Main Content

getSignalIDByIndex

Get signal ID for signal at specified index inSimulink.sdi.Runobject

Description

example

sigID= getSignalIDByIndex(runObj,idx)returns the signal IDsigIDfor the signal at the specified indexidxin theSimulink.sdi.RunobjectrunObj.

Tip

You can use the signal ID to get theSimulink.sdi.Signalobject that contains the signal data and metadata or perform a signal comparison using theSimulink.sdi.compareSignalsfunction.

Examples

collapse all

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

Configure and Simulate the Model

TheslexAircraftExamplemodel 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. TheSimulink.sdi.Run.getLatestfunction returns the most recently created run in the Simulation Data Inspector repository. Use thegetSignalIDByIndexfunction 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

您可以指定公差值使用的comparison as a property in the loggedSimulink.sdi.Signalobject. Use theSimulink.sdi.getSignalfunction to access theSignalobject using the signal ID.

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

Compare Signals

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

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

The comparison result is out of tolerance. You can use theSimulink.sdi.viewfunction to inspect and analyze the comparison results.

Input Arguments

collapse all

Run that contains the desired signal, specified as aSimulink.sdi.Runobject.

Index of the signal within the run, specified as an integer.

Output Arguments

collapse all

Unique numeric signal identifier, returned as an integer.

Introduced in R2012b