Function File: units (fromUnit, toUnit)
Function File: units (fromUnit, toUnit, x)

Return the conversion factor from fromUnit to toUnit measurements.

This is an octave interface to the GNU Units program which comes with an annotated, extendable database defining over two thousand measurement units. See man units or http://www.gnu.org/software/units for more information. If the optional argument x is supplied, return that argument multiplied by the conversion factor. For example, to convert three values from miles per hour into meters per second:

units ("mile/hr", "m/sec", [30, 55, 75])
ans =

  13.411  24.587  33.528

Demonstration 1

The following code

 a.value = 100; a.unit = 'lb';
 b.value =  50; b.unit = 'oz';
 c.unit = 'kg';
 c.value = units(a.unit, c.unit, a.value) + units(b.unit, c.unit, b.value)

Produces the following output

c =

  scalar structure containing the fields:

    unit = kg
    value =  46.777

Package: miscellaneous