separateUnits
Splits a quantity into its numeric part and its units.
Category: Symbolic Computations in MATLAB > Units of Measurement
Syntax
[value, units] = separateUnits(expr)
Returns the part of expr without units and the units part.
Description
separateUnits is the inverse of attaching units by multiplication: value*units gives back the original quantity. With a single output only value is returned. An expression without units yields itself as value.
The pair is handy when a calculation must continue with plain doubles, using double(value), and the units are put back afterwards.
Input arguments
expr- Symbolic quantity, a product of a factor and units.
Output arguments
value- The numeric or symbolic factor.
units- The product of units, such as
[km]/[s].
Example
Value and units of a speed
u = symunit;
[v, un] = separateUnits(3*u.km/u.s)
v*un
Output
v = 3
un = [km]/[s]
ans = 3*([km]/[s])