Convert numbers to engineering notation strings, with prefixes from International System of Units (SI).
- num2eng(23e8) produces the string '2.3G'
- num2eng(0.0000004) produces the string '400n'
Federico Forte (2020). num2eng (https://www.mathworks.com/matlabcentral/fileexchange/13168-num2eng), MATLAB Central File Exchange. Retrieved .
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:
Of all the numeric->prefix M-files the I reviewed, this has the simplest and clearest code, and the author even remembered to place a limit on the "while" loop iterations. It also includes an H1 line and some examples, which is nice. There are mlint messages that need attention, and some input checking and precision control is required (maybe just pass it directly to "num2str"?). A space character between the coefficient and prefix is required by the SI standard, but is missing from this submission, which makes it useless for publishing. Some strings are suboptimal: zero, +-Inf, and NaN all end up with the prefix y (eg: 0 -> '0y'), any value with an order > 27 just adds more zeroes (eg: 1e30 -> '100000000Y'), while values with an order < -28 end up with a messy combination of E-notation and SI prefix (eg: 1e-30 -> '1e-06y').
A similar funtion can found at :
which have spacing between the SI-prefix and number, (as it should have).
Good job. Maybe some checking instructions are needed. It would be nice if you also submitted the "opposite" function eng2num!.