# v_sprintcpx

## PURPOSE

V_SPRINTCPX format a complex number for printing S=(Z,F)

## SYNOPSIS

function s=v_sprintcpx(z,f)

## DESCRIPTION

    V_SPRINTCPX  format a complex number for printing S=(Z,F)

     Usage: fprintf('%s',v_sprintcpx(z));

      Inputs: z   a complex number to print
              f   optional formatting string as in fprintf e.g. '0.2f' [default: 'g']
                  may also include 'i' or 'j' [default] to control sqrt(-1) symbol.

     Outputs: s   formatted output string

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

## SOURCE CODE

    0001 function s=v_sprintcpx(z,f)
    0002 %V_SPRINTCPX  format a complex number for printing S=(Z,F)
    0003 %
    0004 % Usage: fprintf('%s',v_sprintcpx(z));
    0005 %
    0006 %  Inputs: z   a complex number to print
    0007 %          f   optional formatting string as in fprintf e.g. '0.2f' [default: 'g']
    0008 %              may also include 'i' or 'j' [default] to control sqrt(-1) symbol.
    0009 %
    0010 % Outputs: s   formatted output string
    0011
    0012 %      Copyright (C) Mike Brookes 2015
    0013 %      Version: $Id: v_sprintcpx.m 10865 2018-09-21 17:22:45Z dmb $
    0014 %
    0015 %   VOICEBOX is a MATLAB toolbox for speech processing.
    0016 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
    0017 %
    0018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0019 %   This program is free software; you can redistribute it and/or modify
    0020 %   it under the terms of the GNU Lesser General Public License as published by
    0021 %   the Free Software Foundation; either version 3 of the License, or
    0022 %   (at your option) any later version.
    0023 %
    0024 %   This program is distributed in the hope that it will be useful,
    0025 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
    0026 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    0027 %   GNU Lesser General Public License for more details.
    0028 %
    0029 %   You can obtain a copy of the GNU Lesser General Public License from
    0030 %   https://www.gnu.org/licenses/ .
    0031 %
    0032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0033
    0034 if nargin<2 || ~numel(f)
    0035     f='g';
    0036 end
    0037 if any(f=='i')
    0038     ij='i';
    0039 else
    0040     ij='j';
    0041 end
    0042 f((f=='i')|(f=='j'))=[]; % remove i and j specifiers
    0043 if ~numel(f)
    0044     f='g';
    0045 end
    0046 if any(f=='+')
    0047     pl='';
    0048 else
    0049     pl='+';
    0050 end
    0051 f=['%' f];
    0052 a=real(z);
    0053 b=imag(z);
    0054 jx=[1 3 2 4 3 4 1 3 2];
    0055 ix=jx(3*sign(a)+sign(b)+5);
    0056 switch(ix)
    0057     case 1
    0058         s=sprintf([f f ij],a,b);
    0059     case 2
    0060         s=sprintf([f pl f ij],a,b);
    0061     case 3
    0062         s=sprintf(f,a);
    0063     case 4
    0064         s=sprintf([f ij],b);
    0065 end