| Mapping Toolbox™ | ![]() |
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.
unitsratio recognizes the following identifiers for converting units of length:
unitsratio recognizes the following identifiers for converting units of angle:
Unit Name | String(s) |
|---|---|
radian | |
degree |
% 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)
![]() | undotrim | unitstr | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |