# convert

Convert numeric array from one unit into another

Since R2021b

## Syntax

``A2 = convert(A1,unit1,unit2)``
``A2 = convert(A1,unit1,unit2,conversiontype)``

## Description

example

````A2 = convert(A1,unit1,unit2)` converts a numeric array, `A1`, from `unit1` to `unit2` by applying the appropriate scaling factor to the numeric values. `unit1` and `unit2` must be commensurate.```

example

````A2 = convert(A1,unit1,unit2,conversiontype)` lets you select whether to apply affine or linear conversion to thermal units. Affine conversion is the default.```

## Examples

collapse all

Create a unit object:

`u1 = simscape.Unit("m")`
```U1 = m```

Create another unit object, commensurate with the first:

`U2 = simscape.Unit("mm")`
```U2 = mm```

Convert a numeric array from meters to millimeters:

`convert([10 20 30], u1, u2)`
```ans = 10000 20000 30000```

Create a `simscape.Unit` object representing degrees Celsius:

`u1 = simscape.Unit("degC")`
```u1 = degC```

Create another `simscape.Unit` object representing degrees Fahrenheit:

`u2 = simscape.Unit("degF")`
```u2 = degF```

Convert temperatures from Celsius to Fahrenheit using affine conversion:

` convert([0 37 100], u1, u2, 'affine')`
```ans = 32.0000 98.6000 212.0000```

Convert the same temperatures using linear conversion:

` convert([0 37 100], u1, u2, 'linear')`
```ans = 0 66.6000 180.0000```

## Input Arguments

collapse all

Array of numeric values, specified as a scalar, vector, or matrix. The array cannot contain complex values and cannot be sparse.

Example: [1.5 2]

Data Types: `double` | `single`

Physical unit expression, specified as a scalar `simscape.Unit` object.

Example: m

Physical unit expression, specified as a scalar `simscape.Unit` object. `unit1` and `unit2` must be commensurate.

Example: mm

Thermal units often require an affine conversion, that is, a conversion that performs both multiplication and addition. For more information, see About Affine Units. Specify the type of conversion:

• `'affine'` — Perform unit conversion that uses both multiplication and addition.

• `'linear'` — Perform unit conversion by applying just the linear term.

Data Types: `char` | `string`

## Output Arguments

collapse all

Array of numeric values, returned as a scalar, vector, or matrix in the same data type as the input array `A1`, with numeric values scaled according to the conversion factor between the two units, `unit1` and `unit2`.

Example: [1500 2000]

Data Types: `double` | `single`

## Version History

Introduced in R2021b