Main Content

Working with Simulink Units

You can specify physical units on Simulink® signals. For details, see Units in Simulink.

Interface blocks, such as Simulink-PS Converter and PS-Simulink Converter, handle the boundary between the Simscape™ physical network and the Simulink blocks connected to it. These converter blocks also handle the physical signal unit conversions:

  • On a Simulink-PS Converter block, you specify the unit using the Input signal unit parameter. This unit must be commensurate with the unit of the physical signal at the PS output port of the block, which is inferred from the signal destination inside the physical network. The Input signal unit parameter provides information to the Simscape unit manager, which performs the necessary unit conversion and scales the signal value accordingly.

  • On a PS-Simulink Converter block, you specify the unit using the Output signal unit parameter. This unit must be commensurate with the unit of the input physical signal coming into the block. The block applies a gain equal to the conversion factor before outputting the Simulink signal.

If you specify a physical unit on a Simulink signal connected to a Simulink-PS Converter or a PS-Simulink Converter block, the software compares this unit with the unit specified inside the block. If the parameter value does not match the physical unit of the Simulink signal connected to the block, you get a warning.

When you add a new unit to your Simscape unit registry, by using the pm_addunit function, and use this unit inside a Simulink-PS Converter or PS-Simulink Converter block:

  • If your unit definition conflicts with the one in the Simulink database, you get a warning about incompatible unit.

  • If you add a unit that does not exist in the Simulink database, you get a warning about undefined unit.

Note that these warnings apply only to the Simulink database; the Simscape physical network works as expected.

For example, you want to view the motor speed in revolutions per second, rather than revolutions per minute (rpm):

  1. Add a new unit rps, defined in terms or rpm:

    pm_addunit('rps', 1/60, 'rpm');
  2. To open the Permanent Magnet DC Motor example model, in the MATLAB® Command Window, type:

  3. Simulate the model. Examine the simulation results in the Motor RPM scope window.

  4. Open the Sensing subsystem (designated as w in the block diagram), double-click the PS-Simulink Converter block and type rps as the Output signal unit parameter value.

  5. Rerun the simulation.

    The model works correctly, with the scope displaying the results in revolutions per second.

    However, the output Simulink signal of the PS-Simulink Converter block now displays a warning badge, with a message The units 'rps' are undefined. The detailed message explains that the units are not defined in the Simulink unit database.

    If you issue a pm_getunits command, you can see rps in the return unit list, which means that the unit is successfully defined in the Simscape unit registry. In other words, the warning applies only to Simulink unit checking.

  6. To turn off the unit inconsistency warnings, in the MATLAB Command Window, type:


Another way to avoid the unit inconsistency warnings is to add the same units to your Simulink unit database. For information on how to create and load a custom Simulink unit database, see Working with Custom Unit Databases.