File Exchange

image thumbnail

num2str with metric prefix

version (1.37 KB) by Mark T
Converts numbers to strings in engineering notation

1 Download

Updated 12 Aug 2008

View License

Converts numbers to strings in engineering notation. Produces string (array) from numbers with mantissa and metric prefix (every third power of 10 between 1e-24 to 1e24).

Cite As

Mark T (2021). num2str with metric prefix (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (8)

Harry Dymond

Whilst the title of this page ("num2str with metric prefix") is accurate, the description ("Converts numbers to strings in engineering notation") and function name ("num2strEng") are not. SI prefixes are not engineering notation. Engineering notation is scientific notation with the exponent restricted to being an integer multiple of three. For those needing actual engineering notation, my num2eng function offers both engineering notation and SI prefixes, and extensive control over the formatting of the output string:

Stephen Cobeldick

Disclaimer: In the end I could not find any FEX submission that gave the correct outputs for the wide range of test-cases that I tried, so I ended up writing my own function. You can find it here:

Stephen Cobeldick

This submission uses an excellent concept to achieve its goal, and the output strings are pretty close to what is expected: for example the strings always correctly include the space character (even if there is no prefix), and it handles out-of-prefix-range values gracefully. The precision control is handy, but for sigfigs<3 it can return very awkward strings (eg: 1e4 -> '1e+001 k', should simply be '10 k', for 1 sigfig). The main drawback of this submission is the use of "feval", which makes it slow and hard to debug. The addition of an H1 line, some input checking and replacing that superfluous usage of <varargin> with a normal input variable would help tidy the code up, but basically it does what it says on the box.


Very useful. However, there is an error when the input vector contains both a value that needs a prefix, and one that does not. (i.e. [10 0.001]).

Modification to output cell arrays instead of string arrays will fix the error.

Alternatively, changing strvcat to char will also fix the error, but you'll be left with an extra space on those values without a prefix.



Lars Olav Vestland

hm doesnt seems handle the certain tick that is zero

Lars Olav Vestland

Very nice

MATLAB Release Compatibility
Created with R2007a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!