symunit
Access to units of measurement for symbolic expressions.
Category: Symbolic Computations in MATLAB > Units of Measurement
Syntax
u = symunit
Creates the unit container; units are read as fields, such as u.m or u.km.
x = 3*u.km/u.h
Attaches units to numbers and expressions by ordinary arithmetic.
Description
A quantity with a unit is an ordinary symbolic expression in which the unit is a symbolic factor. 3*u.km is three kilometers, u.m/u.s is meters per second, and u.m^2 an area. Because units are symbolic, sums and products follow the usual rules, and unitConvert changes them to other units exactly.
Unit names are case sensitive and follow common abbreviations: m, km, cm, s, min, h, kg, N, J, W, Pa, K, Celsius, ft, mi, L. Units are shown in square brackets, as in 3*[km].
Output arguments
u- Object whose field names are unit names. Each field gives a symbolic unit.
Example
Quantities with units
u = symunit;
x = 3*u.km
v = 5*u.m/u.s
unitConvert(x, u.m)
x = 3*[km]
v = 5*([m]/[s])
ans = 3000*[m]
Notes
In MatLivre symunit must be called without arguments and used through the container u. The form symunit('m') does not return a usable unit, and a few unit names are not defined (for example hour, day and mL; use h, d and cm^3). Results of arithmetic on units have class sym.