findUnits

Finds the units that appear in an expression.

Category: Symbolic Computations in MATLAB > Units of Measurement

Syntax

U = findUnits(expr)

Returns the units present in expr as a row vector.

Description

Each distinct unit is listed once, no matter how many times or with which exponent it occurs. For 5*kg*m/s^2 the result is [kg, m, s]. The numeric factor is not returned; for that, use separateUnits.

It is a quick way to see what dimensions an expression involves before converting it.

Input arguments

expr
Symbolic expression, possibly with units.

Output arguments

U
Row vector of distinct units. Empty when the expression has no units.

Example

Units in a force expression

u = symunit;
findUnits(5*u.kg*u.m/u.s^2)
findUnits(3*u.m/u.s)
findUnits(sym(3))
Output
ans = 
[[kg], [m], [s]]
ans = 
[[m], [s]]
ans = 
Empty sym: 1-by-0

See also

separateUnits isUnit symunit checkUnits