symunit
Units of measurement
Syntax
Description
u = symunit
returns the units collection. Then, specify any unit by using
u.
unit
. For example, specify
3
meters as 3*u.m
. Common alternate names
for units are supported, such as u.meter
and
u.metre
. Plurals are not supported. For details about the
list of available units, see Units and Unit Systems List.
Examples
Limitations
When using symbolic units, the value of
0
times a symbolic unit is returned as a dimensionless0
. To preserve the unit when multiplying a symbolic unit by0
, use a cell array to represent the zero measurement.For example, you can define
0
degrees Celsius as a cell array and convert it to degrees Fahrenheit by using theunitConvert
function.u = symunit; tC = {0,u.Celsius}; tF = unitConvert(tC,u.Fahrenheit,'Temperature','Absolute')
tF = 32*[Fahrenheit]
Tips
You can use tab expansion to find names of units. Type
u.
, press Tab, and continue typing.1
represents a dimensionless unit. Hence,isUnit(sym(1))
returns logical1
(true
).Certain non-linear units, such as decibels, are not implemented because arithmetic operations are not possible for these units.
Instead of using dot notation to specify units, you can alternatively use string input for
symunit(unit)
. For example,symunit("m")
specifies the unit meter.