rewrite

Rewrites a quantity in terms of other units.

Category: Symbolic Computations in MATLAB > Units of Measurement

Syntax

y = rewrite(x, units)

Expresses the derived units in x using the given unit expression.

Description

A derived unit is a shorthand for a product of base units: a newton is kg*m/s^2 and a joule is N*m. rewrite expands or regroups the units of x accordingly. For example rewrite(u.J, u.N*u.m) gives the base form [kg]*[m]^2/[s]^2.

To change the scale of a unit, as from km to m, use unitConvert; rewrite is for changing the unit combination.

Input arguments

x
Symbolic quantity with units.
units
Unit expression in which to express the result, such as u.kg*u.m/u.s^2.

Output arguments

y
Equivalent expression written in the requested units.

Example

Derived units in base units

u = symunit;
rewrite(u.N, u.kg*u.m/u.s^2)
rewrite(u.J, u.N*u.m)
rewrite(1*u.W, u.J/u.s)
Output
ans = ([kg]*[m])/[s]^2
ans = ([kg]*[m]^2)/[s]^2
ans = ([kg]*[m]^2)/[s]^3

Notes

In MatLivre rewrite accepts only unit expressions as the second argument. The named targets 'SI' and 'SIBase' raise an error.

See also

unitConvert symunit baseUnits derivedUnits