Physical Units Toolbox

Version 5.0 (86.2 KB) by Sky Sartorius
Enables operations using hundreds of supported physical units of measurement and physical constants.
3.4K Downloads
Updated 28 Feb 2024

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
Created with R2021a
Compatible with R2016b and later releases
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

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.
Many derived constants updated with defining equations.

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.
Added several constants from physics.nist.gov/cuu/Constants.
Added property validator overloaded methods.

3.0.0.0

toolbox, help text.
Git. More base units. Better, hopefully clearer usage. More methods supported. Updated documentation to help the learning curve.

2.10.0.0

New str2u and surf methods. A few more units added.
Much more emphasis on using the u.m classdef, with documentation updated to reflect.

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!
Methods added: disp, num2str, cumtrapz, numel, isempty, reshape.
Plot method with auto-labeling axes with units.
A few more units added.

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

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.