unitsratio

Unit conversion factors

Syntax

ratio = unitsratio(to,from)

Description

ratio = unitsratio(to,from) returns the number of to units per one from unit. You can specify any of the measurement units supported by the validateLengthUnit function, such as kilometers, or the angle units 'radians' and 'degrees'.

For example, using measurement units, unitsratio('cm','m') returns the value 100 because there are 100 centimeters per meter.

The variables to and from are case insensitive and can be either singular or plural. For example, unitsratio accepts any of the values listed in the following table for angle units.

Unit Name

Acceptable Values

radian

'rad', 'radian(s)'

degree

'deg', 'degree(s)'

The unitsratio function makes it easy to convert values from one system of units to another. For example, if you want to convert the value 100 kilometers (from units) to meters (to units), you can use the following code:

y = unitsratio('meters','kilometers') * 100

y =

      100000

Examples

% Approximate mean earth radius in meters
radiusInMeters = 6371000

% Conversion factor
feetPerMeter = unitsratio('feet', 'meter')

% Radius in (international) feet:
radiusInFeet = feetPerMeter * radiusInMeters

% The following prints a true statement for valid TO, FROM pairs:
to   = 'feet';
from = 'mile';
sprintf('There are %g %s per %s.', unitsratio(to,from), to, from)

% The following prints a true statement for valid TO, FROM pairs:
to   = 'degrees';
from = 'radian';
sprintf('One %s is %g %s.', from, unitsratio(to,from), to)

See Also

| (Image Processing Toolbox)