Convert units of Simulink.sdi.Signal object



convertUnits(sig,units) converts the units of the Simulink.sdi.Signal object sig to the units specified by units. For a list of accepted units, see Allowed Units. You can use the convertUnits function to convert the units of Simulink.sdi.Signal objects that contain data of all built-in and fixed-point types.


collapse all

This example shows how to use the convertUnits function to convert the units of a Simulink.sdi.Signal object, using the model sldemo_autotrans. When you convert the units of the Signal object, the Simulation Data Inspector performs a conversion on the data and updates any plots that display the signal. Changing the units of a Signal object does not affect the model that created the signal.

Generate Simulation Data

Simulate the sldemo_autotrans model to create a run in the Simulation Data Inspector. Then, use the Simulink.sdi.Run.getLatest function to access the Run object that corresponds to the simulation.

out = sim('sldemo_autotrans');

autoRun = Simulink.sdi.Run.getLatest;

Inspect the Signal Properties

Get the Simulink.sdi.Signal object for the EngineRPM signal and check the Units property.

engine_sig = getSignalsByName(autoRun,'EngineRPM');

ans = 

Convert Signal Units

Use the convertUnits function to convert the EngineRPM signal units to rad/s. Then, change the signal name to reflect the new units.

engine_sig.Name = 'EngineFreq,rad/s';

Check the modified signal properties.

ans = 
ans = 

Input Arguments

collapse all

Signal with units to convert, specified as a Simulink.sdi.Signal object.

Desired units for the signal, specified as a string or character vector. For a list of accepted units, see Allowed Units.

Example: 'm'

Example: "ft/s"

Data Types: char | string

Introduced in R2018a