Main Content

isUnit

Determine if input is a symbolic unit

Description

tf = isUnit(expr) returns logical 1 (true) if expr is a unit, or a product of powers of units, and logical 0 (false) if it is not.

example

Examples

Determine if Input is a Unit

Determine if an expression is a symbolic unit by using isUnit.

Test if 3*u.m is a symbolic unit, where u = symunit. The isUnit function returns logical 0 (false) because 3*u.m contains the symbolic number 3.

u = symunit;
isUnit(3*u.m)
ans =
  logical
   0

Check if u.m, u.mW, and x*u.Hz are units, where u = symunit. The isUnit function returns the array [1 1 0], meaning that the first two expressions are units but the third expression is not.

syms x
units = [u.m u.mW x*u.Hz];
isUnit(units)
ans =
  1×3 logical array
   1   1   0

Input Arguments

collapse all

Input, specified as a number, vector, matrix or multidimensional array, or a symbolic number, variable, vector, matrix, multidimensional array, function, or expression.

Tips

  • 1 represents a dimensionless unit. Hence, isUnit(sym(1)) returns logical 1 (true).

Version History

Introduced in R2017a