Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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 between units by using `unitConvert`

.

Convert 1.2 meters to centimeters.

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

len = 120*[cm]

Convert `len`

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

len = unitConvert(len,u.in)

len = (6000/127)*[in]

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

len = 47.2441

Calculate the force needed to accelerate a mass of 5 kg at 2
m/s^{2}.

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

F = 10*(([kg]*[m])/[s]^2)

Convert the result to newton.

F = unitConvert(F,u.N)

F = 10*[N]

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 = 30*[N]*[m]

E = unitConvert(E,u.J)

E = 30*[J]

Convert `E`

to kilowatt-hour.

E = unitConvert(E,u.kWh)

E = (1/120000)*[kWh]

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 = 23*[K]

absK = unitConvert(T,u.K,'Temperature','absolute')

absK = (5923/20)*[K]

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 = 32*[Fahrenheit]

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/s^{2}. 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*u.kg; a = 2*u.m/u.s^2; F = m*a

F = 10*(([kg]*[m])/[s]^2)

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

F = 10*[N]

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 = (1250000000000/17281869297)*(([ft]*[lbm])/[s]^2)

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

F = (20000000000000/8896443230521)*[lbf]

Convert `F`

to CGS derived units.

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

F = 1000000*[dyn]

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

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

loadCell = (300000000/45359237)*[lbm] (125/762)*[ft] (25/508)*[ft] (25/762)*[ft] 14*[Fahrenheit] 104*[Fahrenheit]

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 = (300000000/45359237)*[lbm] (250/127)*[in] (75/127)*[in] (50/127)*[in] 14*[Fahrenheit] 104*[Fahrenheit]

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

.

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

loadCellDouble = 6.6139 1.9685 0.5906 0.3937 14.0000 104.0000

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 = 6.6138678655463274216892140403508*[lbm] 1.968503937007874015748031496063*[in] 0.5905511811023622047244094488189*[in] 0.3937007874015748031496062992126*[in] 14.0*[Fahrenheit] 104.0*[Fahrenheit]

Convert five acres (`ac`

), whose unit is a U.S. survey acre, to
metric area.

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

area = (313632000000/15499969)*[m]^2

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

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 = 0.0000041356676623401643884479280999879*[eV]

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

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

E = 4.1357e-06

After completing calculations, remove the unit system.

removeUnitSystem(phSys)

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

Define these base units:

Dimension | Unit | Implementation |
---|---|---|

Mass | Electron rest mass | `u.m_e` |

Elementary charge | Electron charge | `u.e` |

Length | Bohr radius (a_{0}) | `u.Bohr` |

Time | ħ/E_{h} | Define by using |

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:

Dimension | Unit | Implementation |
---|---|---|

Angular momentum | Reduced Planck's constant | `u.hbar` |

Energy | Hartree | `u.E_h` |

Electric dipole moment | ea_{0} | Define by using |

Magnetic dipole moment | 2 Bohr Magneton = eħ/2m_{e} | Define by using |

Electric potential | E_{h}/e | Define by using |

edm_au = newUnit('edm_au',u.e*u.bohr); mdm_au = newUnit('mdm_au', u.e*u.hbar/(2*u.me)); 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 = "atomicUnits"

Convert the properties of a proton to atomic units.

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

proton = 1836.1559670674356174696928918542*[m_e] 1.0000000000000000578208778346486*[e] 0.0000000000000010204521077472272506008435148061*[edm_au] 0.0015210322058038370229109632800588*[mdm_au]

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

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

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/s

^{2}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')`

.

`baseUnits`

| `derivedUnits`

| `newUnitSystem`

| `removeUnit`

| `removeUnitSystem`

| `symunit`

| `unitConvert`