File Exchange

image thumbnail


version (2.64 KB) by Jason Kaeding
Works just like num2str except will print with formatting in SI prefix notation.

1 Download

Updated 02 Mar 2010

View License

Works just like num2str except will print with formatting in SI prefix notation and (optional) units and precision.

Works with arrays of numbers and (potentially) cell arrays of strings for the units, returning a cell array of strings.


str = num2sci(165.48e-3) returns str = '165.5 m'
str = num2sci(165.48e-3,'V') returns str = '165.5 mV'
str = num2sci(165.48e-3,'mV') returns str = '165.5 uV'
str = num2sci(165.48e-3,3,'V') returns str = '165 mV'
str = num2sci([1.5 2.5],{'V','mA'}) returns str = {'1.5 V' '2.5 mA'}

Cite As

Jason Kaeding (2021). num2sci (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (3)

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 is a well explained function, with a good help section (though no H1 line), some input checking, plenty of examples, and a rather short "See Also" line. The inclusion of precision control is a plus, although it does not always round in the expected direction: it prefers to round down to '1000' and not up to '1' (eg: 0.99999 -> '1000 m', but should simply be '1 '). The space character (required by the SI standard) is usually present, but goes missing if there is no prefix (eg: 1 -> '1', but should be '1 '). For values with an order > 27, it also just adds more zeros to the string (eg: 1e30 -> '1000000 Y', instead of the simpler '1e30 '). The special-case handling for when a prefix is inside the units could be handy. Overall, it is a well behaved function, let down by being quite slow compared to the others that I tested.

Holger Hiebel

I love it and use it very often.

MATLAB Release Compatibility
Created with R2009b
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!