Main Content


Units of measurement



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.


Specify Units of Measurement

Before specifying units, load units by using symunit. Then, specify a unit by using dot notation.

Specify a length of 3 meters. You can also use aliases u.meter or u.metre.

u = symunit;
length = 3*u.m
length =


Use tab expansion to find names of units. Type u., press Tab, and continue typing.

Specify the acceleration due to gravity of 9.81 meters per second squared. Because units are symbolic expressions, numeric inputs are converted to exact symbolic values. Here, 9.81 is converted to 981/100.

g = 9.81*u.m/u.s^2
g =

For more information about the differences between symbolic and numeric arithmetic, see Choose Numeric or Symbolic Arithmetic.

Operations on Units and Conversion to Double

Units behave like symbolic expressions when you perform standard operations on them. For numeric operations, separate the value from the units, substitute for any symbolic parameters, and convert the result to double.

Find the speed required to travel 5 km in 2 hours.

u = symunit;
d = 5*;
t = 2*;
s = d/t
s =

The value 5/2 is symbolic. You may prefer double output, or require double output for a MATLAB® function that does not accept symbolic values. Convert to double by separating the numeric value using separateUnits and then using double.

[sNum,sUnits] = separateUnits(s)
sNum =
sUnits =
sNum = double(sNum)
sNum =

For the complete units workflow, see Units of Measurement Tutorial.

Convert Between Units

Use your preferred unit by rewriting units using unitConvert. Also, instead of specifying specific units, you can specify that the output should be in terms of SI units.

Calculate the force required to accelerate 2 kg by 5 m/s2. The expression is not automatically rewritten in terms of Newtons.

u = symunit;
m = 2*;
a = 5*u.m/u.s^2;
F = m*a
F =

Convert the expression to newtons by using unitConvert.

F = unitConvert(F,u.N)
F =

Convert 5 cm to inches.

length = 5*;
length = unitConvert(length,
length =

Convert length to SI units. The result is in meters.

length = unitConvert(length,'SI')
length =

Simplify Units of Same Dimension

Simplify expressions containing units of the same dimension by using simplify. Units are not automatically simplified or checked for consistency unless you call simplify.

u = symunit;
expr = 300* + 40*u.inch + 2*u.m
expr =
300*[cm] + 40*[in] + 2*[m]
expr = simplify(expr)
expr =

simplify automatically chooses the unit to return. To choose a specific unit, see Convert Between Units.

Temperature: Absolute and Difference Forms

By default, temperatures are assumed to represent temperature differences. For example, 5*u.Celsius represents a temperature difference of 5 degrees Celsius. This assumption allows arithmetical operations on temperature values and conversion between temperature scales.

To represent absolute temperatures, use degrees kelvin so that you do not have to distinguish an absolute temperature from a temperature difference.

Convert 23 degrees Celsius to K, treating the temperature first as a temperature difference and then as an absolute temperature.

u = symunit;
T = 23*u.Celsius;
diffK = unitConvert(T,u.K)
diffK =
absK = unitConvert(T,u.K,'Temperature','absolute')
absK =


  • When using symbolic units, the value of 0 times a symbolic unit is returned as a dimensionless 0. To preserve the unit when multiplying a symbolic unit by 0, 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 the unitConvert function.

    u = symunit;
    tC = {0,u.Celsius};
    tF = unitConvert(tC,u.Fahrenheit,'Temperature','Absolute')
    tF =


  • 1 represents a dimensionless unit. Hence, isUnit(sym(1)) returns logical 1 (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.

Version History

Introduced in R2017a