This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Unit conversion factors


ratio = unitsratio(to,from)


ratio = unitsratio(to,from) returns the number of to units per one from unit. For example, unitsratio('cm','m') returns 100 because there are 100 centimeters per meter. The unitsratio function makes it easy to convert from one system of units to another. Specifically, if x is in units from and

y = unitsratio(to, from) * x

then y is in units to.

to and from can be any strings from the second column of one of the following tables (both must come from the same table). The variables to and from are case insensitive and can be either singular or plural.

Units of Length

unitsratio recognizes the identifiers listed in the validateLengthUnit function.

Units of Angle

unitsratio recognizes the following identifiers for converting units of angle:

Unit Name



'rad', 'radian(s)'


'deg', 'degree(s)'


% 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)
Was this topic helpful?