Documentation

# mixedUnits

Split unit into sum of units

## Syntax

``mixedUnits(quantity,units)``

## Description

example

````mixedUnits(quantity,units)` splits the physical quantity `quantity` into a linear combination of the units in `units`.Units in `units` must be in descending order of magnitude.Units in `quantity` and `units` must be compatible.`quantity` must not contain symbolic variables.```

## Examples

collapse all

Split `8000` seconds into hours, minutes, and seconds by using `mixedUnits`. The result is 2 hours, 13 minutes, and 20 seconds.

```u = symunit; t = 8000*u.s; tunits = [u.hour u.minute u.second]; tSplit = mixedUnits(t,tunits)```
```tSplit = [ 2, 13, 20]```

Customize the displayed output by using `compose`.

`compose("%d hours + %d minutes + %.1f seconds", double(tSplit))`
```ans = "2 hours + 13 minutes + 20.0 seconds"```

Convert the geographic coordinate `15.352°` into degrees (°), arcminutes ('), and arcseconds (''). The result is 15° 21' 36/5''.

```gCoord = 15.352*u.degree; gUnits = [u.degree u.arcmin u.arcsec]; gCoordSplit = mixedUnits(gCoord,gUnits)```
```gCoordSplit = [ 15, 21, 36/5]```

Convert the result from symbolic to floating point by using `double`.

`gCoordDbl = double(gCoordSplit)`
```gCoordDbl = 15.0000 21.0000 7.2000```

Reconstruct the original coordinate by summing the split units and rewriting the result to degrees. `mixedUnits` returns an exact symbolic result instead of a numeric approximation. For details, see Choose Symbolic or Numeric Arithmetic.

```gOrig = sum(gCoordSplit.*gUnits); gOrig = rewrite(gOrig,u.degree)```
```gOrig = (1919/125)*[deg]```

## Input Arguments

collapse all

Input, specified as a symbolic expression with units. `quantity` must not contain symbolic variables. Units in `quantity` and `units` must be compatible.

Units to represent input as, specified as a vector of symbolic units. Units must be in descending order of magnitude. Units in `quantity` and `units` must be compatible.