3.8

3.8 | 5 ratings Rate this file 0 Downloads (last 30 days) File Size: 14.75 KB File ID: #4093

units.m

by Henning Ressing

 

26 Oct 2003 (Updated 10 Nov 2003)

Converts physical unit1 into unit2.

| Watch this File

File Information
Description

y = units(x,'unit1','unit2') - Converts x from physical unit1 to unit2

example: units(1,'in','mm') = 25.4

The following units are supported:
Acceleration: m/s^2, cm/s^2, mm/s^2, ft/s^2, in/s^2, G
Angle: rad, deg, rev
Area: km^2, m^2, cm^2, mm^2, ym^2 (square-micrometer), sq-mile, sq-yd, sq-ft, sq-in,
   acres, ha, ar
Area Moment of Inertia: m^4, cm^4, mm^4, ft^4, in^4
Density: t/m^3 (metric), kg/m^3, g/cm^3, g/mm^3, lbs/ft^3 lbs/in^3, lbs/galUS, lbs/galUK
Energy, Work, Torque: GJ, MJ, kJ, J, mJ, Nm, Ncm, Nmm, kWh, Wh, Ws, lb-ft, lb-in, oz-in,Btu,
   Btu, cal, kcal, eV
Force: MN, kN, N, dyne, lbf, kip
Fuel Consumption: l/100km, miles/galUS
Frequency, Angular Velocity: GHz, MHz, kHz, Hz, 1/s, 1/min, 1/h, rad/s, deg/s, rpm
Length: km, m, dm, cm, mm, ym (micrometer), nm, mile, yard, ft, in, mill,
   Angstrom, light-year
Mass: t (metric), tUS, tUK, kg, g, mg, yg (microgram), ng, lbs, oz
Mass Moment of Inertia: kg*m^2, kg*cm^2, kg*mm^2, g*m^2, g*cm^2, g*mm^2, lb*ft^2, lb*in^2
Power: GW, MW, kW, W, mW, hp, Btu/h, Btu/s, kcal/h, J/h
Pressure, Stress: GPa, MPa, kPa, hPa, Pa, bar, mbar, atm, dyne/cm^2, ksi, psi, mmHg, mmH2O
Strain: m/m, mm/m, ym/m (micrometer/m), nm/m, %, o/oo, in/in, mill/in
Stress Intensity Factor: MPa*m^1/2, MPa*mm^1/2, ksi*in^1/2, psi*in^1/2
Temperature: degK, degC, degF, degR
Time: yr (365 days), mth (30 days), wk, day, hr, min, s, ms, ys (microsecond), ns
Velocity: km/s, km/h, m/s, cm/s, mm/s, m/min, mm/min, mps, mph, ft/s, in/s, ft/min,
   in/min, Mach, knots
Viscosity: Ns/m^2, poise, centipoise, lbfs/sq-ft
Volume: km^3, m^3, cm^3, mm^3, ym^3, cu-mile, cu-ft, cu-in, l, cl, ml, galUS, galUK,
   pint (liquid US), quart (liquid US), fl-oz (liquid US)

Metric Prefixes: Yotta, Zetta, Exa, Peta, Terra, Giga, Mega, Myria, kilo, hecto, 1
    deci, centi, milli, micro, nano, pico, femto, atto, zepto, yocto

CONSISTENCY OF UNITS IS NOT CHECKED FOR!
(i.e., units(1,'m','kg') = 1, which is of course nonsense.)

Acknowledgements
This submission has inspired the following:
Units (updated), Round off dates and times
MATLAB release MATLAB 5.2 (R10)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (8)
16 Dec 2003 Myesha Molea

well i am looking for where a acre,yard,miles,and qarts came from,do you
 have it where is the location.

16 Dec 2003 myesha morgan

Where is the location where i can find where the acre,yard,mile,quart came from.
do you have it on this website?

30 Jul 2004 Kelvin Cruz  
09 Sep 2004 Mark M

This function has been useful to me. The temperature portion for the second unit needs to have the "c" changed to "x", line 648 to 659; Those "temp = size(c);" lines are also not used for anything. This error occurs only when using the temperature conversions. It is easy to fix.

12 Jul 2005 Matt Allen

Great little program with an impressive list of units stored. It's nice to have just to have all of these units listed in one place.

24 Jan 2006 Saidu Waziri

Useful program

12 Mar 2007 Anton Macicek  
17 Dec 2008 Joerg Bretschneider

useful & correct for simple purposes, but not a systematic approach. SI prefixes are incomplete and not handled properly (ym for µm is puzzling, as it has its use for yocto (1e-24)). The code could be written far more compact (1000 lines reduced to 200 using simple concepts)

Please login to add a comment or rating.
Updates
10 Nov 2003

- added units of strain
- fixed forgotten semicolon

Tag Activity for this File
Tag Applied By Date/Time
chemistry Henning Ressing 22 Oct 2008 07:09:05
physics Henning Ressing 22 Oct 2008 07:09:05
unit conversion Henning Ressing 22 Oct 2008 07:09:05
physical Henning Ressing 22 Oct 2008 07:09:05

Contact us at files@mathworks.com