eng
Version 1.0.1 (4.43 KB) by
Clas Nordell
Convert numbers to engineering notation string with SI prefix. Customizable output by name-valued settings, e.g. TeX out, micro character.
eng Convert numbers to engineering notation string with SI prefix
eng(X) converts number X into an engineering string using a prefix letter as multiple according to the SI standard. Also known as metric prefix.
Input X is adjusted so its 3 modulus of exponent is equal to zero.
Example: eng(1234) >> '1.234 k'
eng(12e26) >> '1.2e27'
X can be a vector or a matrix. X = [100 1000 10000] will give a string '100, 1 k, 10 k'.
eng(X,N) will round off X's mantissa to N numbers of deicmals.
eng(1234,2) >> '1.23 k'
Add unit to the output
eng(1234,'Ohm') >> '1.234 kOhm'
Rounding can be used together with unit
eng(1234,2,'Ohm') >> '1.23 kOhm'
It is also possible to convert a number string made by eng back to a numbers. NOTE: TeX string not supported.
eng('1.345 k') >> 1345
eng('1.345 k, 324') >> [1345 324]
eng('100 mOhm') >> 0.1
eng('100 m','m') >> arg2 is the unit in arg1, output will be 100.
[EngOut, Mantissa, Exponent, PrefixStr, Unit] = eng(X) to get all parameters.
Name-value arguments that change the output string and interpret input string
'MicroChar' - Character to use for micro. Default 'µ', char(181). (TeXout can use other)
'CharBeforePrefix' - Characther before prefix. Default ' ' (space) (the SI standard)
'TeXout' - TeX output ready for figures and message boxes. Default 0.
'TeXmicro' - String to use for micro for TeX output. Default 'µ', char(181). Use '\mu' for TeX micro.
'TeXmultiStr' - String for TeX output to put between number and 10. Default '\cdot'. char(215) for '×'
'TeXInfStr' - String for TeX infinity. Default '\infty'
'PrefixAsNum' - Set prefix letter as numbers. E.g. n >> e-9. (TeXout gives \cdot10^...)
'ExpChar' - Exponent character to use when prefix is as number or outside range. Default 'e'.
'InfChar' - Infinity character. Default 'Inf'. Use char(8734) for '∞' (TeXout sets \infty)
'ColDel' - Column delimiter for matrix input. Default ','
'RowDel' - Row delimiter for matrix. Default ';'. Use char(10) for NewLine.
'ExpBase' - Exponent Base output. 0: exp (e.g. 1e3 >> 3) 1: base (e.g. 1e3 >> 1000). Default 0.
Example using name-value arguments
eng(1234,2, 'PrefixAsNum',true, 'TexOut',true) >> ' 1.23\cdot10^3 '
LIMITATIONS
SI prefix h, da, d and c are not supported.
Does not handle complex numbers. For complex numbers do for instance
n, complex number
s = {'-' '+' '+'}; %sign selector
EngOut = [ eng(real(n)) ' ' s{sign(imag(n))+2} ' ' eng(abs(imag(n))) ' i' ]
Cite As
Clas Nordell (2026). eng (https://www.mathworks.com/matlabcentral/fileexchange/106140-eng), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2021a
Compatible with R2019b and later releases
Platform Compatibility
Windows macOS LinuxTags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.