No BSD License  

4.75

4.8 | 5 ratings Rate this file 27 Downloads (last 30 days) File Size: 5.51 KB File ID: #9873

Simple Units and Dimensions for Matlab

by

 

02 Feb 2006 (Updated )

This code provides an effecient, easy to use, method of incorporating real world units ...

| Watch this File

File Information
Description

***Note***
This method of using units is quick and clean. For a more complete version that automatically does dimensional analysis, see the file entitled "Units and Dimensions Suite for Matlab" (See the Acknowledgements section below)
*******

The units.m function returns a struct containing the SI values of many common units. The self-contained help demonstrates how to use this struct to cleanly and effeciently perform matlab calculations using commonly encountered units and physical constants. The code is easily modified to include any non-standard unit or constant desired. This method for handling units was inspired by the methods used by MathCAD.

Acknowledgements

This file inspired Units And Dimensions Suite For Matlab, Fundamental Physical Constants And Unit Conversion In Si (Mks) & Gaussian (Cgs) Units, and Units For Matlab.

MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
13 Mar 2012 Patrik Eschle

Simple and robust, thank you.

I use it in parallel with physunits, that provides more sophisticated units handling, but is more complex and thus more error prone.

Why oh why is this not a Matlab native feature?

12 Mar 2009 Richard Stephens

This is such a simple and elegant way of handling units. I love it!

20 Feb 2006 Rob deCarvalho

Check out the improved way of handling units. Following the suggestions below, I wrote an improved version of units.m which incorporates a matlab class to both display units and enforce dimensional consistency throughout your application. It should post by 2/23/06. Check it out and please let me know off errors/improvements

10 Feb 2006 John D'Errico

Improved now with self contained help. I'd still prefer to see an implementation as a class, but I also recognize this would take a significant amount of work to implement.

08 Feb 2006 Nathaniel Brahms

This file is very useful, and makes entry and conversion of units much simpler than more cumbersome "conversion" programs.

A note on use (this should be shown in the hlep file):
To enter a number in a given unit, MULTIPLY by the unit:
l = 5*u.in;
To display a calculation in a given unit, DIVIDE by the unit:
l/u.m
To convert a number between two units, MULTIPLY by the starting unit, and DIVIDE by the ending unit:
5*u.in/u.m
To enter complicated units, just multiply:
g = 9.8*u.m/u.s^2;

Also, pressure is force divided by area, not times.

06 Feb 2006 Rob deCarvalho

The code was updated on 2/6/05 to include self contained help. The example file has been removed in favor of including it in the self-contained help.
A significant improvement to this code could be achieved by creating a matlab class that would overload all math operations and check the expressions for unit consistency. It could also display results in any desired unit. This would, however, result in significantly increased complexity to ensure bug-free operation. In its current form, units.m is compact and very simple to incorporate into more complicated calculations.

05 Feb 2006 John D'Errico

The example file is reasonably short. It absolutely should be merged into the help for units itself. As it is, the function units has NO self-contained help. An example function "unitsExample" is poor matlab programming style. If I am running Matlab and need to remember how to use units, how should I remember that the help for it is in the function unitsExample.m? This biased my rating lower than it might have been. Some might argue my rating should be lower still. Its easily fixed though, and I hope/assume the author will choose to repair this serious flaw so I will leave the rating as a 3.
Units itself is a simple, clean tool that does work as the author claims. A second reason I did not rate it higher is because part of me thinks this application does cry out for a slicker tool that will display the units automatically. I'd like to see something that will see you multiply force times area, and understand the result is a pressure and display the proper units with no thought required on the part of the user.
I'll note that this was created using R14 SP3, but it has no properties that prevent it from being used in much older releases, as long as they allow the use of structures.

Updates
07 Feb 2006

Example file has been moved into the help section and is no longer included as a separate file.

07 Feb 2006

Updating the description and title to this post.

21 Feb 2006

Updating the file description to reference the improved version

Contact us