File Exchange

image thumbnail

MetricPrefixStr - Print SI Prefix Formatted Numbers

version (1.71 KB) by Damon Bradley
Prints a SI prefix formatted string corresponding to a numeric vector.

1 Download

Updated 29 Mar 2013

View License

Author: Damon Bradley
Purpose: Print out formatted string using SI prefixes to clean up plots
for quantities in the thousands, millions, billions and trillions. This is useful for
publication-quality plots.

Version 1.0, March 28, 2013

INPUTS: xtickvec - Any vector of numbers
OUTPUTS: str - An array of strings with properly formatted numbers


labels = MetricPrefixStr([1 10 100 33.64 1000 2000 40000 340000 7000000 1e14])

labels =

'1' '10' '100' '33.64' '1k' '2k' '40k' '340k' '7M' '100T'

class labels

ans =


Cite As

Damon Bradley (2021). MetricPrefixStr - Print SI Prefix Formatted Numbers (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (2)

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

While it claims to be suitable for "publication-quality plots", the lack of the space character between the coefficient and the prefix means that this submission actually does not follow the SI standard. It also entirely lacks the prefixes y, z, a, f, p, n, u, m, P, E, Z, and Y. And while it gives some examples, the example on line 20 "class labels" shows a basic misunderstanding between Command Syntax and Function Syntax in MATLAB:

The code could be much simpler: the use of (slow) "repmat" is not required (just use the format string itself, eg: '%d k', etc), and that whitespace removal code is bizarre: why not simply "strtrim(xtick)" ?. Precision control, returning my NaN values, an H1 line and input checking would be nice too!

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