This is a static copy of a profile report

Home

num2str (Calls: 7, Time: 0.015 sec)
Generated 28-May-2016 14:58:48 using performance time.
function in file /home/johs/MATLAB/R2015b/toolbox/matlab/strfun/num2str.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
cmxCreate_cpufunction7
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
71
if isreal(x)
70.005 s33.8%
72
s = int2str(x); % Enhance the ...
70.003 s20.0%
35
narginchk(1,2);
70.002 s12.3%
70
if isequaln(x, fix(x)) &&a...
70.002 s12.1%
60
if nargin < 2 || (isinteger...
70.001 s9.6%
All other lines  0.002 s12.2%
Totals  0.015 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
int2strfunction70.002 s16.0%
Self time (built-ins, overhead, etc.)  0.013 s84.0%
Totals  0.015 s100% 
Code Analyzer results
No Code Analyzer messages.
Coverage results
Show coverage for parent directory
Total lines in function164
Non-code lines (comments, blank lines)59
Code lines (lines that can run)105
Code lines that did run23
Code lines that did not run82
Coverage (did run/can run)21.90 %
Function listing
time 
Calls 
 line
   1 
function s = num2str(x, f)
   2 
%NUM2STR Convert numbers to a string.
   3 
%   T = NUM2STR(X) converts the matrix X into a string representation T
   4 
%   with about 4 digits and an exponent if required.  This is useful for
   5 
%   labeling plots with the TITLE, XLABEL, YLABEL, and TEXT commands.
   6 
%
   7 
%   T = NUM2STR(X,N) converts the matrix X into a string representation
   8 
%   with a maximum N digits of precision.  The default number of digits is
   9 
%   based on the magnitude of the elements of X.
  10 
%
  11 
%   T = NUM2STR(X,FORMAT) uses the format string FORMAT (see SPRINTF for
  12 
%   details).
  13 
%
  14 
%   Example 1:
  15 
%       num2str(randn(2,2),3) produces a string matrix such as
  16 
%
  17 
%        1.44    -0.755
  18 
%       0.325      1.37
  19 
%
  20 
%   Example 2:
  21 
%       num2str(rand(2,3) * 9999, '%10.5e\n') produces a string matrix
  22 
%       such as
  23 
%
  24 
%       8.14642e+03
  25 
%       1.26974e+03
  26 
%       6.32296e+03
  27 
%       9.05701e+03
  28 
%       9.13285e+03
  29 
%       9.75307e+02
  30 
%
  31 
%   See also INT2STR, SPRINTF, FPRINTF, MAT2STR.
  32 

  33 
%   Copyright 1984-2012 The MathWorks, Inc.
  34 
%------------------------------------------------------------------------------
< 0.01 
      7 
  35 
    narginchk(1,2); 
< 0.01 
      7 
  36 
    if ischar(x) 
  37 
        s = x;
  38 
        return;
  39 
    end
      7 
  40 
    if isempty(x) 
  41 
        s = '';
  42 
        return
  43 
    end
< 0.01 
      7 
  44 
    if ~isnumeric(x) && ~islogical(x) 
  45 
        error(message('MATLAB:num2str:nonNumericInput') );
  46 
    end
< 0.01 
      7 
  47 
    if isfloat(x) 
< 0.01 
      7 
  48 
        x = 0+x;  % Remove negative zero 
      7 
  49 
    end 
      7 
  50 
    if issparse(x) 
  51 
        x = full(x);
  52 
    end
< 0.01 
      7 
  53 
    intFieldExtra = 1; 
      7 
  54 
    maxFieldWidth = 12; 
< 0.01 
      7 
  55 
    floatWidthOffset = 4; 
      7 
  56 
    forceWidth = 0; 
      7 
  57 
    padColumnsWithSpace = true; 
  58 
    % Compose sprintf format string of numeric array.
  59 
        
< 0.01 
      7 
  60 
    if nargin < 2 || (isinteger(x) && isnumeric(f)) 
  61 
        
  62 
        % To get the width of the elements in the output string
      7 
  63 
        widthCopy = x; 
  64 
        % replace Inf and NaN with a number of equivalent length (3 digits) for width
  65 
        % calcultion
< 0.01 
      7 
  66 
        if isfloat(x) 
< 0.01 
      7 
  67 
            widthCopy(~isfinite(widthCopy)) = 314; %This could be any 3 digit number 
      7 
  68 
        end 
< 0.01 
      7 
  69 
        xmax = double(max(abs(widthCopy(:)))); 
< 0.01 
      7 
  70 
        if isequaln(x, fix(x)) && (isinteger(x) || eps(xmax) <= 1) 
< 0.01 
      7 
  71 
            if isreal(x) 
< 0.01 
      7 
  72 
                s = int2str(x); % Enhance the performance 
< 0.01 
      7 
  73 
                return; 
  74 
            end         
  75 

  76 
            d = min(maxFieldWidth, floor(log10(xmax)) + 1);
  77 
            forceWidth = d+intFieldExtra;
  78 
            f = '%d';
  79 
        else
  80 
            % The precision is unspecified; the numeric array contains floating point
  81 
            % numbers.
  82 
            if xmax == 0
  83 
                d = 1;
  84 
            else
  85 
                d = min(maxFieldWidth, max(1, floor(log10(xmax))+1))+floatWidthOffset;
  86 
            end
  87 
            
  88 
            [s, forceWidth, f] = handleNumericPrecision(x, d);
  89 

  90 
            if ~isempty(s)
  91 
                return;
  92 
            end
  93 
        end
  94 
    elseif isnumeric(f)
  95 
        f = round(real(f));
  96 

  97 
        [s, forceWidth, f] = handleNumericPrecision(x, f);
  98 

  99 
        if ~isempty(s)
 100 
            return;
 101 
        end
 102 
    elseif ischar(f)
 103 
        % Precision is specified as an ANSI C print format string.
 104 
        
 105 
        % Explicit format strings should be explicitly padded
 106 
        padColumnsWithSpace = false;
 107 
        
 108 
        % Validate format string
 109 
        k = strfind(f,'%');
 110 
        if isempty(k)
 111 
            error(message('MATLAB:num2str:fmtInvalid', f));
 112 
        end
 113 
    else
 114 
        error(message('MATLAB:num2str:invalidSecondArgument'))        
 115 
    end
 116 

 117 
    %-------------------------------------------------------------------------------
 118 
    % Print numeric array as a string image of itself.
 119 

 120 
    if isreal(x)
 121 
        [raw, isLeft] = cellPrintf(f, x, false);
 122 
        [m,n] = size(raw);
 123 
        cols = cell(1,n);
 124 
        widths = zeros(1,n);
 125 
        for j = 1:n
 126 
            if isLeft
 127 
                cols{j} = char(raw(:,j));
 128 
            else
 129 
                cols{j} = strvrcat(raw(:,j));
 130 
            end
 131 
            widths(j) = size(cols{j}, 2);
 132 
        end
 133 
    else
 134 
        forceWidth = 2*forceWidth + 2;
 135 
        raw = cellPrintf(f, real(x), false);
 136 
        imagRaw = cellPrintf(f, imag(x), true);
 137 
        [m,n] = size(raw);
 138 
        cols = cell(1,n);
 139 
        widths = zeros(1,n);
 140 
        for j = 1:n
 141 
            cols{j} = [strvrcat(raw(:,j)) char(imagRaw(:,j))];
 142 
            widths(j) = size(cols{j}, 2);
 143 
        end
 144 
    end
 145 

 146 
    maxWidth = max([widths forceWidth]);
 147 
    padWidths = maxWidth - widths;
 148 
    padIndex = find(padWidths, 1);
 149 
    while ~isempty(padIndex)
 150 
        padWidth = padWidths(padIndex);
 151 
        padCols = (padWidths==padWidth);
 152 
        padWidths(padCols) = 0;
 153 
        spaceCols = char(ones(m,padWidth)*' ');
 154 
        cols(padCols) = strcat({spaceCols}, cols(padCols));
 155 
        padIndex = find(padWidths, 1);
 156 
    end
 157 

 158 
    if padColumnsWithSpace
 159 
        spaceCols = char(ones(m,1)*' ');
 160 
        cols = strcat(cols, {spaceCols});
 161 
    end
 162 

 163 
    s = strtrim([cols{:}]);
 164 
end

Other subfunctions in this file are not included in this listing.