unitsratio - Unit conversion factors

Syntax

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. unitsratio 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). to and from are case insensitive and can be either singular or plural.

Units of Length

unitsratio recognizes the following identifiers for converting units of length:

Unit Name

String(s)

Meter

'm', 'meter(s)', 'metre(s)'

Centimeter

'cm', 'centimeter(s)', 'centimetre(s)'

Millimeter

'mm', 'millimeter(s)', 'millimetre(s)'

Micron

'micron(s)'

Kilometer

'km', 'kilometer(s)', 'kilometre(s)'

Nautical mile

'nm', 'nautical mile(s)'

International foot

'ft', 'international ft', 'foot', 'international foot', 'feet', 'international feet'

Inch

'in', 'inch', 'inches'

Yard

'yd', 'yard(s)'

international mile

'mi', 'mile(s)', 'international mile(s)'

U.S. survey foot

'sf', 'survey ft', 'U.S. survey ft', 'survey foot', 'U.S. survey foot', 'survey feet', 'U.S. survey feet'

U.S. survey mile (statute mile)

'sm', 'survey mile(s)', 'statute mile(s)', 'U.S. survey mile(s)'

Units of Angle

unitsratio recognizes the following identifiers for converting units of angle:

Unit Name

String(s)

radian

'rad', 'radian(s)'

degree

'deg', 'degree(s)'

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)
  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS