newUnit

Defines a new unit in terms of existing ones.

Category: Symbolic Computations in MATLAB > Units of Measurement

Syntax

newUnit(name, value)

Defines the unit name as equal to the quantity value.

u = newUnit(name, value)

Also returns the new unit.

Description

After newUnit('Beer', 330*u.cm^3) the unit Beer is a field of every new symunit object and can be used in conversions: 2 Beer is 33/50 L. The definition holds until it is removed with removeUnit or the session ends.

Create a fresh container with u = symunit after defining the unit, as an existing one does not see it.

Input arguments

name
Name of the unit, a valid identifier.
value
Quantity that equals one of the new unit, such as 330*u.cm^3.

Output arguments

u
The newly defined unit.

Example

A custom volume unit

u = symunit;
newUnit('Beer', 330*u.cm^3);
u = symunit;
unitConvert(2*u.Beer, u.L)
removeUnit('Beer');
Output
ans = (33/50)*[l]

See also

removeUnit symunit unitConvert newUnitSystem