# unitConversionFactor

Conversion factor between units

## Description

example

C = unitConversionFactor(unit1,unit2) returns the conversion factor C between units unit1 and unit2 so that unit1 = C*unit2.

example

C = unitConversionFactor(unit1,unit2,'Force',true) forces unitConversionFactor to return a conversion factor even if the units are not dimensionally compatible.

## Examples

collapse all

Find the conversion factor between inches and centimeters.

u = symunit;
inch2cm = unitConversionFactor(u.inch,u.cm)
inch2cm =
127/50

Convert the conversion factor to double.

inch2cm = double(inch2cm)
inch2cm =
2.5400

Find the conversion factor between Newtons and kg m/s2. The conversion factor is 1.

convFactor = unitConversionFactor(1*u.N, 1*u.kg*u.m/u.s^2)
convFactor =
1

Convert between units quickly by using text input as a shortcut. Convert 3 inch to cm.

3*double(unitConversionFactor("inch","cm"))
ans =
7.6200

Convert between dimensionally incompatible units by specifying the argument 'Force' as true.

Convert between Watts and Joules. unitConversionFactor returns the factor 1/[s] because 1 W = 1 J/s.

u = symunit;
convFactor = unitConversionFactor(u.W, u.J, 'Force', true)
convFactor =
1/[s]

If you do not specify 'Force' as true, then unitConversionFactor returns an error.

unitConversionFactor(u.W, u.J)
Error using unitConversionFactor (line 81)
Incompatible units.

## Input Arguments

collapse all

Units, specified as a character vector, string, or symbolic units.

## Version History

Introduced in R2017a