This is a static copy of a profile reportHome
num2str (14010 calls, 4.897 sec)
Generated 05-Nov-2014 07:52:34 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/matlab/strfun/num2str.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
67 | s = int2str(x); | 11686 | 2.133 s | 43.6% |  |
90 | [s, forceWidth, f] = handleNum... | 2324 | 0.871 s | 17.8% |  |
40 | narginchk(1,2); | 14010 | 0.330 s | 6.7% |  |
65 | if ~isempty(x) && iseq... | 14010 | 0.260 s | 5.3% |  |
46 | if isempty(x) | 14010 | 0.120 s | 2.5% |  |
All other lines | | | 1.182 s | 24.1% |  |
Totals | | | 4.897 s | 100% | |
Children (called functions)
Function Name | Function Type | Calls | Total Time | % Time | Time Plot |
int2str | function | 11686 | 1.893 s | 38.7% |  |
num2str>handleNumericPrecision | subfunction | 2324 | 0.811 s | 16.6% |  |
Self time (built-ins, overhead, etc.) | | | 2.193 s | 44.8% |  |
Totals | | | 4.897 s | 100% | |
Code Analyzer results
No Code Analyzer messages.Coverage results
[ Show coverage for parent directory ]
Total lines in function | 166 |
Non-code lines (comments, blank lines) | 62 |
Code lines (lines that can run) | 104 |
Code lines that did run | 26 |
Code lines that did not run | 78 |
Coverage (did run/can run) | 25.00 % |
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 % If the input array is integer-valued, num2str returns the exact string
15 % representation of that integer. The term integer-valued includes large
16 % floating-point numbers that lose precision due to limitations of the
17 % hardware.
18 %
19 % Example 1:
20 % num2str(randn(2,2),3) produces the string matrix
21 %
22 % -0.433 0.125
23 % -1.671 0.288
24 %
25 % Example 2:
26 % num2str(rand(2,3) * 9999, '%10.5e\n') produces the string matrix
27 %
28 % 8.14642e+003
29 % 1.26974e+003
30 % 6.32296e+003
31 % 9.05701e+003
32 % 9.13285e+003
33 % 9.75307e+002
34 %
35 % See also INT2STR, SPRINTF, FPRINTF, MAT2STR.
36
37 % Copyright 1984-2010 The MathWorks, Inc.
38 % $Revision: 5.32.4.25 $ $Date: 2011/04/16 06:40:15 $
39 %------------------------------------------------------------------------------
0.33 14010 40 narginchk(1,2);
41 % If input is a string, return this string.
0.08 14010 42 if ischar(x)
43 s = x;
44 return
45 end
0.12 14010 46 if isempty(x)
47 s = '';
48 return
49 end
0.08 14010 50 if isfloat(x)
0.09 14010 51 x = 0+x; % Remove negative zero
0.02 14010 52 end
0.06 14010 53 if issparse(x)
54 x = full(x);
55 end
56
0.05 14010 57 intFieldExtra = 1;
0.07 14010 58 maxFieldWidth = 12;
0.06 14010 59 floatWidthOffset = 4;
0.03 14010 60 forceWidth = 0;
0.05 14010 61 padColumnsWithSpace = true;
62
63 % Compose sprintf format string of numeric array.
0.09 14010 64 if nargin < 2
0.26 14010 65 if ~isempty(x) && isequalwithequalnans(x, fix(x))
0.06 11686 66 if isreal(x)
2.13 11686 67 s = int2str(x);
0.04 11686 68 return;
69 else
70 % Complex case
71 xmax = double(max(abs(x(:))));
72 if xmax == 0
73 d = 1;
74 else
75 d = min(maxFieldWidth, floor(log10(xmax)) + 1);
76 end
77 forceWidth = d+intFieldExtra;
78 f = '%d';
79 end
0.02 2324 80 else
81 % The precision is unspecified; the numeric array contains floating point
82 % numbers.
0.08 2324 83 xmax = double(max(abs(x(:))));
0.04 2324 84 if xmax == 0
85 d = 1;
0.01 2324 86 else
2324 87 d = min(maxFieldWidth, max(1, floor(log10(xmax))+1))+floatWidthOffset;
2324 88 end
89
0.87 2324 90 [s, forceWidth, f] = handleNumericPrecision(x, d);
91
0.01 2324 92 if ~isempty(s)
2324 93 return;
94 end
95 end
96 elseif isnumeric(f)
97 f = round(real(f));
98
99 [s, forceWidth, f] = handleNumericPrecision(x, f);
100
101 if ~isempty(s)
102 return;
103 end
104 elseif ischar(f)
105 % Precision is specified as an ANSI C print format string.
106
107 % Explicit format strings should be explicitly padded
108 padColumnsWithSpace = false;
109
110 % Validate format string
111 k = strfind(f,'%');
112 if isempty(k)
113 error(message('MATLAB:num2str:fmtInvalid', f));
114 end
115 else
116 error(message('MATLAB:num2str:invalidSecondArgument'))
117 end
118
119 %-------------------------------------------------------------------------------
120 % Print numeric array as a string image of itself.
121
122 if isreal(x)
123 [raw, isLeft] = cellPrintf(f, x, false);
124 [m,n] = size(raw);
125 cols = cell(1,n);
126 widths = zeros(1,n);
127 for j = 1:n
128 if isLeft
129 cols{j} = char(raw(:,j));
130 else
131 cols{j} = strvrcat(raw(:,j));
132 end
133 widths(j) = size(cols{j}, 2);
134 end
135 else
136 forceWidth = 2*forceWidth + 2;
137 raw = cellPrintf(f, real(x), false);
138 imagRaw = cellPrintf(f, imag(x), true);
139 [m,n] = size(raw);
140 cols = cell(1,n);
141 widths = zeros(1,n);
142 for j = 1:n
143 cols{j} = [strvrcat(raw(:,j)) char(imagRaw(:,j))];
144 widths(j) = size(cols{j}, 2);
145 end
146 end
147
148 maxWidth = max([widths forceWidth]);
149 padWidths = maxWidth - widths;
150 padIndex = find(padWidths, 1);
151 while ~isempty(padIndex)
152 padWidth = padWidths(padIndex);
153 padCols = (padWidths==padWidth);
154 padWidths(padCols) = 0;
155 spaceCols = char(ones(m,padWidth)*' ');
156 cols(padCols) = strcat({spaceCols}, cols(padCols));
157 padIndex = find(padWidths, 1);
158 end
159
160 if padColumnsWithSpace
161 spaceCols = char(ones(m,1)*' ');
162 cols = strcat(cols, {spaceCols});
163 end
164
165 s = strtrim([cols{:}]);
166 end
Other subfunctions in this file are not included in this listing.