Main Content

Unit Conversions and Unit Systems

Convert between units with Symbolic Math Toolbox™. This page shows conversions between units and between systems of units, such as SI, CGS, or a user-defined unit system.

Convert Units

Convert between units by using unitConvert.

Convert 1.2 meters to centimeters.

u = symunit;
len = 1.2*u.m;
len = unitConvert(len,
len =

Convert len to inches. The result is in exact symbolic form. Separate units and convert to double.

len = unitConvert(len,
len =
[len units] = separateUnits(len);
len = double(len)
len =

Calculate the force needed to accelerate a mass of 5 kg at 2 m/s2.

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

Convert the result to newton.

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


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

Calculate the energy when force F is applied for 3 meters. Convert the result to joule.

d = 3*u.m;
E = F*d
E =
E = unitConvert(E,u.J)
E =

Convert E to kilowatt-hour.

E = unitConvert(E,u.kWh)
E =

Temperature Unit Conversion

Temperatures can represent either absolute temperatures or temperature differences. By default, temperatures are assumed to be differences. Convert temperatures assuming temperatures are absolute by specifying the 'Temperature' input as 'absolute'.

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

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

Because the value 0 is dimensionless and 0 degrees cannot be represented, convert 0 degrees between temperature units by using cell input.

Convert 0 degrees Celsius to degrees Fahrenheit.

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

Convert to SI, CGS, or US Unit Systems

Automatically convert to the correct units by converting to a unit system. Further, converting to the derived units of a unit system attempts to select convenient units. Available unit systems include SI, CGS, and US. For all unit systems, see Unit Systems List. In addition, you can define custom unit systems.

Calculate the force due to a 5 kg mass accelerating at 2 m/s2. The resulting units are hard to read. Convert them to convenient units by specifying the SI and Derived options. unitConvert automatically chooses the correct units of newton.

u = symunit;
m = 5*;
a = 2*u.m/u.s^2;
F = m*a
F =
F = unitConvert(F,'SI','Derived')
F =

Convert F to US units. By default, the converted units are base units. For convenience, also convert into derived units by specifying the Derived option. The derived units are easier to read.

F = unitConvert(F,'US')
F =
F = unitConvert(F,'US','Derived')
F =

Convert F to CGS derived units.

F = unitConvert(F,'CGS','Derived')
F =

Convert a specification in SI to US derived units. Specify the temperatures as absolute.

loadCell = [   3*;      % capacity
              50*;      % length
              15*;      % width
              10*;      % height
             -10*u.Celsius; % minimum temperature
              40*u.Celsius; % maximum temperature
loadCell = unitConvert(loadCell,'US','derived','Temperature','absolute')
loadCell =

If unitConvert does not choose your preferred unit, then adjust the result with further unitConvert commands. Here, inches are more convenient than feet. Convert the result to inches.

loadCell = unitConvert(loadCell,u.inch)
loadCell =

The exact symbolic values are hard to read. Separate the units and convert to double.

[loadCellDouble loadCellUnits] = separateUnits(loadCell);
loadCellDouble = double(loadCellDouble)
loadCellDouble =

Alternatively, approximate the result to high precision by using vpa. The vpa function also keeps the symbolic units because it returns symbolic output.

loadCell = vpa(loadCell)
loadCell =

Convert five acres (ac), whose unit is a U.S. survey acre, to metric area.

u = symunit;
area = 5*u.ac_US;
area = unitConvert(area,'SI')
area =

Define Custom Unit System from Existing System

Custom unit systems provide flexibility in converting units. You can easily define a custom unit system by modifying a default unit system. Alternatively, you can define the system directly. For definitions of unit system, base units, and derived units, see Unit System Definition.

In photonics, commonly used units are nanosecond (ns), electron volt (eV), and nanometer (nm). Define a unit system with these units by modifying the SI unit system. Get SI base and derived units by using baseUnits and derivedUnits. Modify the units by using subs.

u = symunit;
bunits = baseUnits('SI');
bunits = subs(bunits,[u.m u.s],[u.nm u.ns])
bunits =
[ [kg], [ns], [nm], [A], [cd], [mol], [K]]
dunits = derivedUnits('SI');
dunits = subs(dunits,u.J,u.eV)
dunits =
[ [F], [C], [S], [H], [V], [eV], [N], [lx], [lm], [Wb], [W], [Pa],...
 [Ohm], [T], [Gy], [Bq], [Sv], [Hz], [kat], [rad], [sr], [Celsius]]


Do not define variables called baseUnits and derivedUnits because the variables prevent access to the baseUnits and derivedUnits functions.

Define the new unit system by using newUnitSystem.

phSys = newUnitSystem('photonics',bunits,dunits)
phSys = 

Calculate the energy of a photon of frequency 1 GHz and convert the result to derived units of the phSys system. The result is in electron volts.

f = 1*u.GHz;
E = u.h_c*f;
E = unitConvert(E,phSys,'Derived')
E =

The exact symbolic result is hard to read. Separate the units and convert to double.

[E Eunits] = separateUnits(E);
E = double(E)
E =

After completing calculations, remove the unit system.


Define Custom Unit System Directly

Define a custom unit system for atomic units (au).

Define these base units:

MassElectron rest massu.m_e
Elementary chargeElectron chargeu.e
LengthBohr radius (a0)u.Bohr

Define by using newUnit.

u = symunit;
t_au = newUnit('t_au',u.hbar/u.E_h);
bunits = [u.m_e u.e u.Bohr u.t_au]
bunits =
[ [m_e], [e], [a_0], [t_au]]

Define these derived units:

Angular momentumReduced Planck's constantu.hbar
Electric dipole momentea0

Define by using newUnit.

Magnetic dipole moment2 Bohr magneton = eħ/2me

Define by using newUnit.

Electric potentialEh/e

Define by using newUnit.

edm_au = newUnit('edm_au',u.e*u.bohr);
mdm_au  = newUnit('mdm_au', u.e*u.hbar/(2*;
ep_au  = newUnit('ep_au', u.E_h/u.e);
dunits = [u.hbar u.E_h u.edm_au u.mdm_au u.ep_au]
dunits =
[ [h_bar], [E_h], [edm_au], [mdm_au], [ep_au]]

Define the unit system.

auSys = newUnitSystem('atomicUnits',bunits,dunits)
auSys = 

Convert the properties of a proton to atomic units.

proton = [  1.672621923e-27*;      % mass
            1.6021766208e-19*u.C;      % charge
            5.4e-24*u.e*;          % electric dipole moment
            1.4106067873e-26*u.J/u.T;  % magnetic dipole moment
proton = unitConvert(proton,auSys,'Derived')
proton =

After completing calculations, remove the unit system and the added units.

removeUnit([u.t_au u.edm_au u.mdm_au u.ep_au])

Unit System Definition

A unit system is a collection of base units and derived units that follows these rules:

  • Base units must be independent in terms of the dimensions mass, time, length, electric current, luminous intensity, amount of substance, and temperature. Therefore, a unit system has up to 7 base units. As long as the independence is satisfied, any unit can be a base unit, including units such as newton or watt.

  • A unit system can have less than 7 base units. For example, mechanical systems need base units only for the dimensions length, mass, and time.

  • Derived units in a unit system must have a representation in terms of the products of powers of the base units for that system. Unlike base units, derived units do not have to be independent.

  • Derived units are optional and added for convenience of representation. For example, kg m/s2 is abbreviated by newton.

  • An example of a unit system is the SI unit system, which has 7 base units: kilogram, second, meter, ampere, candela, mol, and kelvin. There are 22 derived units found by calling derivedUnits('SI').

See Also

| | | | | |

Related Topics

External Websites