Code covered by the BSD License  

Highlights from
Velocity Conversion Toolbox

5.0

5.0 | 3 ratings Rate this file 7 Downloads (last 30 days) File Size: 8.52 KB File ID: #31665
image thumbnail

Velocity Conversion Toolbox

by Jonathan Sullivan

 

03 Jun 2011 (Updated 09 Jun 2011)

Convert velocities between mph, m/s,km/h, kts, ft/s

| Watch this File

File Information
Description

This toolbox contains 20 very simple functions that will convert between 5 very popular units of measure of velocity. The supported units are as follows:

  1. Miles per hour (statute mile)
  2. Meters per second
  3. Kilometers per hour
  4. Knots (nautical miles per hour)
  5. Feet per second (U.S. survey feet)

These functions are called much like their distance-converting counterparts (i.e. nm2km, nm2sm, etc).

The convention for naming these functions are as follow:

    [unitsFrom]2[unitsTo]

where [unitsFrom] and [unitsTo] can be any one of the following tags:

  1. mph (miles per hour)
  2. mps (meters per second)
  3. kmph (kilometers per hour)
  4. kts (nautical miles per hour)
  5. ftps (feet per second)

For example, to convert from knots to meters per second.

  vel_kts = 100;
  vel_mps = kts2mph(vel_kts);
  disp(vel_mps)

* UPDATE *
Also included is a function called veldim. This is very similar to MATLAB's distdim. It takes in the velocity, the units it is in, and the units you want to convert it to.

vel = veldim(vel,unitsFrom,unitsTo)

Acknowledgements
This submission has inspired the following:
Unit Converters
MATLAB release MATLAB 7.12 (2011a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (7)
06 Jun 2011 Joachim  
06 Jun 2011 Mike Sheppard  
07 Jun 2011 Sean de

Well done! The blackbird tops it off.

08 Jun 2011 Sean de

One suggestion:
Have an mfile called something like "vnames" or something that does nothing but have a help section. Thus you could type:
help vnames
and it would give you a list of all conversion functions and velocity abbreviations.

09 Jun 2011 Jonathan Sullivan

@Sean de
I've now included a function in the toolbox called veldim. You might want to check that out. In the help file it has links to all the other functions in the toolbox. Also, it takes in strings of the unitsFrom and unitsTo in order to handle units that aren't known beforehand. It will take in the full unit's name and/or abbreviations. For example: you could input vel = veldim(vel,'mph','kmph') -OR- vel = veldim(vel,'miles per hour','kilometers per hour') and get the same result.

Hope this helps!

16 Jun 2011 Wolfgang Schwanghart

Another suggestion:
Instead of having so many functions, wouldn't it be easier to have one function with the units as input parameters? For example

mph = velconvert(mps,'unitin','unitout')

But I guess this is a matter of taste.

16 Jun 2011 Jonathan Sullivan

@Wolfganga

I have included such a function, namely veldim, thanks to the suggestion of Sean de. With this you may do exactly what you want to do.

Example:
mph = veldim(mps,'mps','mph')

Because of the string processing and error checking required in such a function, it can be quite a bit slower than the direct conversion call (i.e. mph = mps2mph(mps);). In fact, for scalars, veldim is approximately 30x slower than its direct counterpart. The difference is less noticeable for vectors. For vectors with 1000 elements, you still take a performance hit of 9-10x.

I've included both types so you are welcome to use whichever way suits you best.

Hope you enjoy it.

Please login to add a comment or rating.
Updates
06 Jun 2011

Add a picture...

09 Jun 2011

Added veldim function, much like MATLAB's distdim

Tag Activity for this File
Tag Applied By Date/Time
velocity Jonathan Sullivan 03 Jun 2011 15:03:28
conversion Jonathan Sullivan 03 Jun 2011 15:03:28
units Jonathan Sullivan 03 Jun 2011 15:03:28
miles per hour Jonathan Sullivan 03 Jun 2011 15:03:28
feet per second Jonathan Sullivan 03 Jun 2011 15:03:28
knots Jonathan Sullivan 03 Jun 2011 15:03:28
kilometers per hour Jonathan Sullivan 03 Jun 2011 15:03:28
meters per second Jonathan Sullivan 03 Jun 2011 15:03:28

Contact us at files@mathworks.com