unitConversionFactor

Factor that converts one unit into another.

Category: Symbolic Computations in MATLAB > Units of Measurement

Syntax

k = unitConversionFactor(u1, u2)

Returns the number k such that 1*u1 equals k*u2.

Description

The factor is a rational number whenever both units have rational definitions, which is the case for the metric and imperial units. For instance the factor from mi to km is 25146/15625, which is exactly 1.609344.

It is the number that unitConvert multiplies by, and is useful when only the ratio is needed, for example to scale an array of plain numbers.

Input arguments

u1
Source unit or unit expression.
u2
Target unit with the same dimension.

Output arguments

k
Exact symbolic conversion factor.

Example

Factors between units

u = symunit;
unitConversionFactor(u.km, u.m)
unitConversionFactor(u.h, u.s)
k = unitConversionFactor(u.mi, u.km)
double(k)
Output
ans = 1000
ans = 3600
k = 25146/15625
ans = 1.6093

See also

unitConvert symunit rewrite double