str2symunit
Converts text describing units into a symbolic unit expression.
Category: Symbolic Computations in MATLAB > Units of Measurement
Syntax
U = str2symunit(text)
Parses text such as 'm/s' or 'kg*m^2/s^2'.
Description
The text uses the same abbreviations as the fields of symunit. The result is the same expression you would build by hand with u.m/u.s, so it can be multiplied by numbers and passed to unitConvert.
It is the inverse of symunit2str, which turns a unit expression back into text. Unknown names raise an error.
Input arguments
text- Character vector or string with unit names combined with
*,/and^.
Output arguments
U- Symbolic unit expression.
Example
Parsing unit strings
U = str2symunit('kg*m^2/s^2')
isUnit(U)
unitConvert(3*U, str2symunit('N*m'))
Output
U = ([kg]*[m]^2)/[s]^2
ans = logical
1
ans = 3*[N]*[m]