Physical Units Toolbox
Editor's Note:This file was selected as MATLAB CentralPick 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 (2022).Physical Units Toolbox(https://github.com/sky-s/physical-units-for-matlab), GitHub. Retrieved.
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxTags
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
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.