unitConvert
Converts a quantity to other units.
Category: Symbolic Computations in MATLAB > Units of Measurement
Syntax
y = unitConvert(x, u2)
Converts x to the unit or unit expression u2.
y = unitConvert(x, 'SI')
Converts x to SI units.
y = unitConvert(___, 'Temperature', mode)
With 'absolute', converts temperatures as readings, not as differences (default 'difference').
Description
The conversion multiplies the number by the ratio between the units, using exact rational factors, so 60 mi/h in km/h is a fraction instead of a rounded decimal. Use double on the numeric part to get a decimal.
Units of different dimensions cannot be converted into one another. Temperatures need care: 'difference' treats Celsius and K as scales of an interval, while 'absolute' includes the offset, so 100 Celsius is 212 Fahrenheit.
Input arguments
x- Symbolic quantity with units.
u2- Target unit, such as
u.m, or a combination likeu.km/u.h. 'Temperature''difference'(default) or'absolute'.
Output arguments
y- Quantity expressed in the target units, as an exact symbolic value.
Example
Length, speed and temperature
u = symunit;
unitConvert(3*u.km, u.m)
unitConvert(5*u.m/u.s, u.km/u.h)
unitConvert(100*u.Celsius, u.Fahrenheit, 'Temperature', 'absolute')
ans = 3000*[m]
ans = 18*([km]/[h])
ans = 212*[Fahrenheit]
Notes
In MatLivre a unit system name as target works for 'SI'; 'CGS' and 'US' are accepted but return the quantity in SI units. Converting between units of different dimensions does not raise an error and returns the quantity unchanged.
See also
symunit unitConversionFactor rewrite checkUnits separateUnits