Main Content

simscape.Unit

Represent unit of measure without an associated value

Since R2021b

Description

simscape.Unit represents units of measure without an associated value, and therefore lets you write MATLAB® functions that emulate the unit propagation behavior.

simscape.Unit is an array of units, which means that it can represent multiple units of measure at the same time. However, you can use only scalar simscape.Unit objects to specify units in simscape.Value objects.

Creation

Description

Unit = simscape.Unit creates a unit. Unit is a 1x1 array of unit 1.

example

Unit = simscape.Unit(1) creates a unit. Unit is a 1x1 array of unit 1.

example

Unit = simscape.Unit(CHR) converts CHR to a unit. Unit is a 1x1 unit array that contains the unit obtained by parsing CHR. CHR must be a valid unit expression, specified as a character vector or string.

example

Unit = simscape.Unit(C) converts cell array C to a unit array. Each element of C must be a character vector that represents a valid unit expression. Unit is the same size as C.

example

Unit = simscape.Unit(S) converts string array S to a unit array. Each element of S must be nonmissing and must represent a valid unit expression. Unit is the same size as S.

example

Object Functions

commensurateCheck whether units are mutually commensurate
computationalDetermine computational unit for commensurate units
convertConvert numeric array from one unit into another

You can also use the typical MATLAB array operations, including dimension queries, concatenation, indexing, and so on. simscape.Unit cannot be used to index into other array object. For more information, see Working with simscape.Value and simscape.Unit Objects.

Examples

collapse all

Create a unit:

U1 = simscape.Unit("m/s")
U1 = 

    m/s

Create another unit:

 U2 = simscape.Unit("m^2/(m*s^2)")
U2 = 

   m/s^2

Canonicalization is a process for converting data that has more than one possible representation into a canonical form. In this example, simscape.Unit canonicalizes unit expressions by canceling exponents, as necessary.

Perform a math operation on the two units, emulating unit propagation behavior:

U3 = U2/U1
U3 = 

    1/s

Limitations

  • Direct block parameterization is not supported, that is, you cannot use simscape.Unit objects directly to specify block parameters. You can use these objects only during programmatic model construction.

  • You cannot use simscape.Unit objects to specify values with units or perform unit computations in Symbolic Math Toolbox™.

  • MATLAB Coder™ does not support simscape.Unit objects.

  • You can use MAT-files to save and load simscape.Unit objects. However, unit derivation is not saved with the units, so if a simscape.Unit is saved with a unit and loaded in a subsequent MATLAB session where some part of the unit is not defined, then MATLAB issues a warning and the object results in an invalid variable.

Version History

Introduced in R2021b

expand all