File Exchange

image thumbnail

MetricPrefixStr - Print SI Prefix Formatted Numbers

version 1.0 (1.71 KB) by

Prints a SI prefix formatted string corresponding to a numeric vector.

0 Downloads

Updated

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

USAGE EXAMPLE:

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 =

char

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:
http://www.mathworks.com/matlabcentral/fileexchange/33174

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:
http://www.mathworks.com/help/matlab/ref/syntax.html

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
MATLAB 7.8 (R2009a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today