Home > voicebox > sprintsi.m

sprintsi

PURPOSE ^

SPRINTSI Print X with SI multiplier S=(X,D,W)

SYNOPSIS ^

function s=sprintsi(x,d,w)

DESCRIPTION ^

SPRINTSI Print X with SI multiplier S=(X,D,W)
 D is number of decimal places (+ve) or significant digits (-ve) [default=-3]
 |W| is total width including multiplier
 if W<=0 then trailing 0's will be eliminated

 Example: sprintsi(2345,-2) gives '2.3 k'

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function s=sprintsi(x,d,w)
0002 %SPRINTSI Print X with SI multiplier S=(X,D,W)
0003 % D is number of decimal places (+ve) or significant digits (-ve) [default=-3]
0004 % |W| is total width including multiplier
0005 % if W<=0 then trailing 0's will be eliminated
0006 %
0007 % Example: sprintsi(2345,-2) gives '2.3 k'
0008 
0009 %      Copyright (C) Mike Brookes 1998
0010 %      Version: $Id: sprintsi.m 4966 2014-08-05 18:20:41Z dmb $
0011 %
0012 %   VOICEBOX is a MATLAB toolbox for speech processing.
0013 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
0014 %
0015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0016 %   This program is free software; you can redistribute it and/or modify
0017 %   it under the terms of the GNU General Public License as published by
0018 %   the Free Software Foundation; either version 2 of the License, or
0019 %   (at your option) any later version.
0020 %
0021 %   This program is distributed in the hope that it will be useful,
0022 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0023 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0024 %   GNU General Public License for more details.
0025 %
0026 %   You can obtain a copy of the GNU General Public License from
0027 %   http://www.gnu.org/copyleft/gpl.html or by writing to
0028 %   Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.
0029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0030 
0031 if nargin<3 w=0; end;
0032 if nargin<2 d=-3; end;
0033 f='afpnum kMGT';
0034 e=max(-18,min(12,floor(log10(abs(x)))));
0035 k=floor(e/3);
0036 dp=max([0 d 3*k-d-e-1]);
0037 if w<=0 & dp
0038    w=abs(w);
0039    dp=max(find([1 mod(mod(round(x*10^(dp-3*k)),10^dp),10.^(dp:-1:1))]))-1;
0040 end
0041 if(k)
0042    s=sprintf(sprintf('%%%d.%df %c',max(w-2,0),dp,f(k+7)),x*1e-3^k);
0043 else
0044    s=sprintf(sprintf('%%%d.%df ',max(w-1,0),dp),x*1e-3^k);
0045 end

Generated on Fri 22-Sep-2017 19:37:38 by m2html © 2003