Physical Units Toolbox
Editor's Note: This file was selected as MATLAB Central Pick of the Week
If the Physical Units Toolbox is on your MATLAB path, there is nothing to initialize, import, add to your workspace, or pass to functions - simply multiply/divide by u.(unitName) to attach physical units to a variable. For example, to define a speed using a supported unit: carSpeed = 100 * u.kph. Or, define a speed with an unsupported unit as a combination of supported units: snailSpeed = 20 * u.m/u.week.
Variables with physical units attached are of the class DimVar ("dimenensioned variable"). Math operations performed on dimensioned variables will automatically perform dimensional analysis and can create new units or cancel units and return a normal variable.
On a global or per-project basis, you can customize to use the base unit system of your choice (e.g. ft-lb-s instead of the SI m-kg-s), as well as customize preferred display units. Display units for any given variable can also be customized. Variables will display in the command window or plot, etc. in terms of those units.
Most common Matlab functions will work with physical units, including many types of plots (with added axis labels).
Cite As
Sky Sartorius (2024). Physical Units Toolbox (https://github.com/sky-s/physical-units-for-matlab), GitHub. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- Aerospace and Defense > Aerospace Toolbox > Standard Workflow Procedures > Physical and Time Unit Conversions >
Tags
Acknowledgements
Inspired by: Units and Dimensions Suite for Matlab, DISPDISP - verbose display of structures and objects
Inspired: Standard Atmosphere Functions, Fuel fraction sizing, Simple propulsion performance estimation, compphysiol
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
.tests
@DimVar
Versions that use the GitHub default branch cannot be downloaded
Version | Published | Release Notes | |
---|---|---|---|
5.0 | Constants updates for the 2019 redefinition of SI base units.
|
|
|
4.3 | Axis labels for plots now use the custom display units associated with the arguments. |
|
|
4.2.0.0 | Recent update changed output syntax of displayparser method, so in the unlikely case that you use that (mostly internal) utility method in your code, you may have backward-compatibility issues, hence incrementing the version number. |
|
|
4.1.0.0 | Per-variable custom display units and other updates. |
|
|
4.0.0.0 | simplified, cleaner, faster, easier-to-maintain scheme (not back-compatible) |
|
|
3.1.0.0 | Added many units to mirror ww.mathworks.com/help/physmod/simscape/ug/unit-definitions.html and www.mathworks.com/help/symbolic/units-list.html.
|
|
|
3.0.0.0 | toolbox, help text.
|
||
2.10.0.0 | New str2u and surf methods. A few more units added.
|
||
2.6.0.0 | added sort method |
||
2.5.0.0 | mm-g-s common system added. |
||
2.4.0.0 | upload error |
||
2.3.0.0 | Added atan2, plot3, cat, plus other minor tweaks. |
||
2.2.0.0 | Plot method updated for R2015b, added isfinite and validateattributes methods, added u classdef functionality. |
||
2.1.0.0 | Preferred display units, updated documentation, some new methods. |
|
|
1.18.0.0 | Fixed error with Rankine. |
|
|
1.17.0.0 | Class name change!
|
|
|
1.16.0.0 | New, simpler, and fuller-functioning methods. |
||
1.15.0.0 | Added ability to switch base unit systems; added many more units; added 'dummy' unitsOf and u2num functions to keep from crashing when calling with non-DimensionedVariable arguments (addresses user concern) |
||
1.14.0.0 | added pressure, angle, and angular velocity units; added static method for working with string representations of units. |
||
1.13.0.0 | added features to unitslist method |
||
1.12.0.0 | Improved unitslist; added kp force unit. |
||
1.11.0.0 | Added new static method 'unitslist' that makes it easy to drastically speed up code developed using the class. |
||
1.10.0.0 | Fixed bug in displaying units with no numerator |
||
1.8.0.0 | New display method looks much better (in response to comments on rob's original post); new classdef structure |
||
1.6.0.0 | new subsasgn method; new html documentation; reworked help blocks; other updates |
||
1.4.0.0 | Documentation and examples; added functionality to u2num; added meshgrid function |
||
1.3.0.0 | added some units |
||
1.2.0.0 | added many units and did a lot of checking an updating so that more units meet their exact definitions |
||
1.0.0.0 |