Main Content


Convert units to other units of measurement



unitConvert(expr,units) converts symbolic units in the expression expr to the units units, where units can be a compound unit or a vector of units.


unitConvert(expr,unitSystem) converts expr to the unit system unitSystem. By default, the SI, CGS, and US unit systems are available. You can also define custom unit systems by using newUnitSystem.

unitConvert(expr,unitSystem,'Derived') converts units to derived units of unitSystem.


___ = unitConvert(___,'Temperature',convMode) indicates whether temperatures represent absolute temperatures or temperature differences by specifying 'absolute' or 'difference' respectively, using input arguments in the previous syntaxes. The 'Temperature' argument affects only conversion between units of temperature. By default, temperatures are assumed to be differences.


collapse all

Convert 5 cm to inches. Because the calculation is symbolic, unitConvert returns a symbolic fractional result.

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

If conversion is not possible, unitConvert returns the input.

Convert length to floating point by separating the value using separateUnits and converting using double. Alternatively, keep the units by using vpa instead of double.

ans =
ans =

For more complex workflows, see Unit Conversions and Unit Systems.

Calculate the force required to accelerate 2 kg by 5 m/s2. The result is not automatically in newtons.

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

Convert F to newtons by using unitConvert.

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

Convert 5 km per hour to meters per second by specifying meters per second as a compound unit.

u = symunit;
ans =

Specify multiple units for conversion by specifying the second argument as a vector of units. This syntax lets you specify units for every dimension to get the desired units.

Convert 5 km per hour to centimeters per minute.

u = symunit;
f = 5*;
units = [ u.min];
ans =

Instead of converting to specific units, you can convert to units of a unit system, such as SI, CGS, or US.

Convert 5 meters to the 'US' unit system. unitConvert returns the result in feet.

u = symunit;
ans =

Convert 10 newtons to derived units in CGS by using the input 'Derived'. The result is in dynes. Repeat the conversion without the input 'Derived' to get a result in base units.

F = 10*u.N;
cgsDerived = unitConvert(F,'CGS','Derived')
cgsDerived =
cgsBase = unitConvert(F,'CGS')
cgsBase =

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 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 =

Input Arguments

collapse all

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

Units to convert input to, specified as a symbolic unit or vector of symbolic units.

Unit system to convert input to, specified as a string or character vector. By default, the SI, CGS, and US unit systems are available. You can also define custom unit systems. See Unit Conversions and Unit Systems.

Temperature conversion mode, specified as 'difference' or 'absolute'.


  • 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 =

Version History

Introduced in R2018b