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).
Mark T (2020). num2str with metric prefix (https://www.mathworks.com/matlabcentral/fileexchange/20950-num2str-with-metric-prefix), MATLAB Central File Exchange. Retrieved .
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:
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:
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.
hm doesnt seems handle the certain tick that is zero
Incorrect use of cat, instead of strvcat was causing error for some input vectors...oops!