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.
unitsratio recognizes the identifiers listed in the validateLengthUnit function.
unitsratio recognizes the following identifiers for converting units of angle:
% 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)