newUnitSystem
Define unit system
Description
newUnitSystem(
defines a new Unit System with the name
name
,baseUnits
)name
and the base units baseUnits
.
Now, you can convert units into the new unit system by using
rewrite
. By default, available unit systems include SI,
CGS, and US. For all unit systems, see Unit Systems List.
newUnitSystem(
additionally specifies the derived units name
,baseUnits
,derivedUnits
)derivedUnits
.
Examples
Define New Unit System from Existing System
A unit system is a collection of units to express quantities.
The easiest way to define a new unit system is to modify a default unit system,
such as SI
, CGS
, or
US
.
Modify SI
to use kilometer for length and hour for time
by getting the base units using baseunits
and modifying
them by using subs
.
u = symunit; SIUnits = baseUnits('SI')
SIUnits = [ [kg], [s], [m], [A], [cd], [mol], [K]]
newUnits = subs(SIUnits,[u.m u.s],[u.km u.hr])
newUnits = [ [kg], [h], [km], [A], [cd], [mol], [K]]
Note
Do not define a variable called baseUnits
because
the variable will prevent access to the baseUnits
function.
Define the new unit system SI_km_hr
using the new base
units.
newUnitSystem('SI_km_hr',newUnits)
ans = "SI_km_hr"
Rewrite 5 meter/second to the SI_km_hr
unit system. As
expected, the result is in terms of kilometers and hours.
rewrite(5*u.m/u.s,'SI_km_hr')
ans = 18*([km]/[h])
Specify Base and Derived Units Directly
Specify a new unit system by specifying the base and derived units directly. A unit system has up to 7 base units. For details, see Unit System.
Define a new unit system with these base units: gram, hour, meter, ampere, candela, mol, and celsius. Specify these derived units: kilowatt, newton, and volt.
u = symunit; sysName = 'myUnitSystem'; bunits = [u.g u.hr u.m u.A u.cd u.mol u.Celsius]; dunits = [u.kW u.N u.V]; newUnitSystem(sysName,bunits,dunits)
ans = "myUnitSystem"
Rewrite 2000 Watts to the new system. By default,
rewrite
uses base units, which can be hard to
read.
rewrite(2000*u.W,sysName)
ans = 93312000000000000*(([g]*[m]^2)/[h]^3)
Instead, for readability, rewrite 2000 Watts to derived units of myUnitSystem
by
specifying 'Derived'
as the third argument. Converting to
the derived units of a unit system attempts to select convenient units. The
result uses the derived unit, kilowatt, instead of base units. For more
information, see Unit Conversions and Unit Systems.
rewrite(2000*u.W,sysName,'Derived')
ans = 2*[kW]
Input Arguments
name
— Name of unit system
string | character vector
Name of unit system, specified as a string or character vector.
baseUnits
— Base units of unit system
vector of symbolic units
Base units of unit system, specified as a vector of symbolic units. The base units must be independent in terms of the dimensions mass, time, length, electric current, luminous intensity, amount of substance, and temperature. Thus, in a unit system, there are up to 7 base units.
derivedUnits
— Derived units of unit system
vector of symbolic units
Derived units of unit system, specified as a vector of symbolic units. Derived units are optional and added for convenience of representation.
More About
Unit System
A unit system is a collection of base units and derived units that follows these rules:
Base units must be independent in terms of the dimensions mass, time, length, electric current, luminous intensity, amount of substance, and temperature. Therefore, a unit system has up to 7 base units. As long as the independence is satisfied, any unit can be a base unit, including units such as newton or watt.
A unit system can have less than 7 base units. For example, mechanical systems need base units only for the dimensions length, mass, and time.
Derived units in a unit system must have a representation in terms of the products of powers of the base units for that system. Unlike base units, derived units do not have to be independent.
Derived units are optional and added for convenience of representation. For example, kg m/s2 is abbreviated by newton.
An example of a unit system is the SI unit system, which has 7 base units: kilogram, second, meter, ampere, candela, mol, and kelvin. There are 22 derived units found by calling
derivedUnits('SI')
.
Version History
Introduced in R2017b
See Also
baseUnits
| derivedUnits
| newUnit
| removeUnitSystem
| rewrite
| symunit
| unitSystems
External Websites
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)