Code covered by the BSD License  

Highlights from
Velocity Conversion Toolbox

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

Velocity Conversion Toolbox



03 Jun 2011 (Updated )

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

| Watch this File

File Information

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:


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);

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)


This file inspired Unit Converters.

MATLAB release MATLAB 7.12 (R2011a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
16 Jun 2011 Jonathan Sullivan


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.

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.

Comment only
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.

Comment only
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!

Comment only
08 Jun 2011 Sean de

Sean de (view profile)

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.

Comment only
07 Jun 2011 Sean de

Sean de (view profile)

Well done! The blackbird tops it off.

06 Jun 2011 Mike Sheppard

Mike Sheppard (view profile)

06 Jun 2011 Joachim  
06 Jun 2011 1.1

Add a picture...

09 Jun 2011 1.2

Added veldim function, much like MATLAB's distdim

Contact us