File Exchange

image thumbnail

Velocity Conversion Toolbox

version 1.2 (8.52 KB) by

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

3 Downloads

Updated

View License

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)

Comments and Ratings (7)

@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.

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.

@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!

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.

Sean de

Sean de (view profile)

Well done! The blackbird tops it off.

Mike Sheppard

Mike Sheppard (view profile)

Joachim

Updates

1.2

Added veldim function, much like MATLAB's distdim

1.1

Add a picture...

MATLAB Release
MATLAB 7.12 (R2011a)
Acknowledgements

Inspired: Unit Converters

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video