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
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])
'1' '10' '100' '33.64' '1k' '2k' '40k' '340k' '7M' '100T'
Damon Bradley (2020). MetricPrefixStr - Print SI Prefix Formatted Numbers (https://www.mathworks.com/matlabcentral/fileexchange/41000-metricprefixstr-print-si-prefix-formatted-numbers), 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:
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!