Main Content

convert

Convert array of numeric values into different unit

Description

example

V2 = convert(V1,unit) converts an array of numeric values contained in the simscape.Value object, V1, into the specified unit, unit, by applying the appropriate scaling factor to the numeric values of V1 and binding the new unit, unit, to V2. unit must be commensurate with the unit of V1.

example

V2 = convert(V1,unit,conversiontype) lets you select whether to apply affine or linear conversion to thermal units. Affine conversion is the default.

Examples

collapse all

Create a simscape.Value object, in meters per second squared:

V1 = simscape.Value([10 20 30], 'm/s^2')
V1 = 

    10    20    30

    : m/s^2

Convert the array into millimeters per second squared:

 V2 = convert(V1, 'mm/s^2')
V2 = 

       10000       20000       30000

    : mm/s^2

Create a simscape.Value object in degrees Celsius:

T = simscape.Value(10, 'degC')
T = 

    10 : degC

Convert the object into Kelvin by performing affine conversion:

 T_affine = convert(T, 'K', 'affine')
T_affine =

    283.1500 : K

Convert the object into Kelvin by performing linear conversion:

 T_linear = convert(T, 'K', 'linear')
T_linear =

    10 : K

Input Arguments

collapse all

Array of numeric values with unit, specified as a simscape.Value object.

Example: 10 : m/s^2

Physical unit expression, specified as a character vector, nonmissing string scalar, or a scalar simscape.Unit object. The expression can consist of valid physical unit names, numbers, math operators, such as +, -, *, /, and ^, and parentheses to specify the order of operations. unit must be commensurate with the unit of V1.

Example: 'mm/s^2'

Data Types: char | string

Thermal units often require an affine conversion, that is, a conversion that performs both multiplication and addition. For more information, see About Affine Units. When you extract values from a simscape.Value object that has affine units, you can specify the type of conversion:

  • 'affine' — Perform unit conversion that uses both multiplication and addition.

  • 'linear' — Perform unit conversion by applying just the linear term.

Data Types: char | string

Output Arguments

collapse all

Array of numeric values with unit, returned as a simscape.Value object.

Example: 10000 : mm/s^2

Version History

Introduced in R2021b