2 function [s,mantissa,factor,
unit,exponent,prefix] =
formatPrefixSI(x,numspec,unitspec,base,nonSI)
4 if nargin<5 % Use traditional units: c, d, da, h.
8 if nargin<4 || isempty(base); % Reference base for the number (if not 10^0)
10 elseif ~isscalar(base)
11 error('Number base must be a real scalar');
20 if nargin<2 || isempty(numspec) % Number format specification
24 % Formats numbers with units
27 error('Input number must be a scalar.');
28 elseif x==0 || isinf(x);
31 exponent = log10(x)+base;
40 EXPONENT = [-24 -21 -18 -15 -12 -9 -6 -3 -2 -1 0 1 2 3 6 9 12 15 18 21 24];
41 PREFIX = {
'y' 'z' 'a' 'f' 'p' 'n' 'u' 'm' 'c' 'd' '' 'da' 'h' 'k' 'M' 'G' 'T' 'P' 'E' 'Z' 'Y'};
43 [~,idx] = intersect(EXPONENT,[-2 -1 1 2]);
48 idx = find(EXPONENT<=exponent,1,
'last');
49 exponent = EXPONENT(idx);
51 idx = find(EXPONENT==exponent,1);
54 factor = 10^(base-exponent);
56 unit = [prefix unitspec];
57 s = sprintf([numspec
' ' unit],mantissa);
Superclass: basic building block to hold functions.