unitConvert
Convert units to other units of measurement
Syntax
Description
converts symbolic units in the input expression to the specified symbolic units.
If the conversion is not possible, convertedExpr = unitConvert(expr,units)unitConvert returns the
input expression without converting it.
converts symbolic units in the input expression to the base units of the
specified unit system.convertedExpr = unitConvert(expr,unitSystem)
You can specify unitSystem as one of these predefined
unit systems: "SI", "CGS",
"US", "GU", "ESU",
or "EMU". Alternatively, you can specify a custom unit system
defined by using the newUnitSystem function.
specifies whether to use the base units or derived units of the specified unit
system by specifying convertedExpr = unitConvert(expr,unitSystem,unitMode)unitMode as "base" or
"derived". If you convert to the "SI"
unit system, you can also specify unitMode as
"constants" to convert the units in the input expression
to the seven SI-defining constants.
specifies whether temperatures in the input expression represent absolute
temperatures or temperature differences. Specify convertedExpr = unitConvert(___,Temperature=tempMode)tempMode as
"absolute" or "difference" after any
of the input argument combinations in the previous syntaxes. By default,
temperatures are assumed to represent differences during conversion.
Examples
Input Arguments
Output Arguments
Tips
When you use symbolic units, the value of
0multiplied by a symbolic unit, such as0*u.Celsius, is returned as a dimensionless0. To preserve the unit when multiplying a symbolic unit by0, use a cell array to represent the zero measurement.For example, you can define
0degrees Celsius as a cell array and convert it to degrees Fahrenheit by using theunitConvertfunction.u = symunit; tC = {0,u.Celsius}; tF = unitConvert(tC,u.Fahrenheit,Temperature="absolute")tF = 32*[Fahrenheit]
Version History
Introduced in R2018b