isUnit

Tests whether a symbolic object is a unit.

Category: Symbolic Computations in MATLAB > Units of Measurement

Syntax

tf = isUnit(S)

Returns true if S consists only of units, with no numeric factor.

Description

A single unit such as u.m and a unit expression such as u.m/u.s give true. A quantity with a number, like 3*u.m, gives false, as does a number or a variable.

This distinction matters for functions that need a pure unit as an argument, for example the target of unitConvert.

Input arguments

S
Symbolic expression.

Output arguments

tf
Logical scalar.

Example

Units versus quantities

u = symunit;
isUnit(u.m)
isUnit(u.m/u.s)
isUnit(3*u.m)
isUnit(sym(3))
Output
ans = logical
   1
ans = logical
   1
ans = logical
   0
ans = logical
   0

See also

symunit findUnits separateUnits checkUnits