This is a static copy of a profile reportHome
num2str (548 calls, 0.087 sec)
Generated 05-Aug-2011 13:00:40 using cpu time.
function in file /usr/local/MATLAB/R2011a/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 |
70 | s = int2str(x); | 546 | 0.044 s | 50.0% |  |
67 | if nargin < 2 | 548 | 0.022 s | 25.0% |  |
64 | padColumnsWithSpace = true; | 548 | 0.011 s | 12.5% |  |
105 | return; | 2 | 0 s | 0% |  |
104 | if ~isempty(s) | 2 | 0 s | 0% |  |
All other lines | | | 0.011 s | 12.5% |  |
Totals | | | 0.087 s | 100% | |
Children (called functions)
Function Name | Function Type | Calls | Total Time | % Time | Time Plot |
int2str | function | 546 | 0.044 s | 50.0% |  |
num2str>handleNumericPrecision | subfunction | 2 | 0 s | 0% |  |
Self time (built-ins, overhead, etc.) | | | 0.044 s | 50.0% |  |
Totals | | | 0.087 s | 100% | |
Code Analyzer results
No Code Analyzer messages.Coverage results
[ Show coverage for parent directory ]
Total lines in function | 169 |
Non-code lines (comments, blank lines) | 63 |
Code lines (lines that can run) | 106 |
Code lines that did run | 22 |
Code lines that did not run | 84 |
Coverage (did run/can run) | 20.75 % |
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.23 $ $Date: 2010/11/22 02:46:50 $
39 %------------------------------------------------------------------------------
40 % if input does not exist or is empty, throw an exception
548 41 if nargin<1
42 error(message('MATLAB:num2str:NumericArrayUnspecified'))
43 end
44 % If input is a string, return this string.
548 45 if ischar(x)
46 s = x;
47 return
48 end
548 49 if isempty(x)
50 s = '';
51 return
52 end
548 53 if isfloat(x)
548 54 x = 0+x; % Remove negative zero
548 55 end
548 56 if issparse(x)
57 x = full(x);
58 end
59
548 60 intFieldExtra = 1;
548 61 maxFieldWidth = 12;
548 62 floatWidthOffset = 4;
548 63 forceWidth = 0;
0.01 548 64 padColumnsWithSpace = true;
65
66 % Compose sprintf format string of numeric array.
0.02 548 67 if nargin < 2
546 68 if ~isempty(x) && isequalwithequalnans(x, fix(x))
546 69 if isreal(x)
0.04 546 70 s = int2str(x);
546 71 return;
72 else
73 % Complex case
74 xmax = double(max(abs(x(:))));
75 if xmax == 0
76 d = 1;
77 else
78 d = min(maxFieldWidth, floor(log10(xmax)) + 1);
79 end
80 forceWidth = d+intFieldExtra;
81 f = '%d';
82 end
83 else
84 % The precision is unspecified; the numeric array contains floating point
85 % numbers.
86 xmax = double(max(abs(x(:))));
87 if xmax == 0
88 d = 1;
89 else
90 d = min(maxFieldWidth, max(1, floor(log10(xmax))+1))+floatWidthOffset;
91 end
92
93 [s, forceWidth, f] = handleNumericPrecision(x, d);
94
95 if ~isempty(s)
96 return;
97 end
98 end
2 99 elseif isnumeric(f)
2 100 f = round(real(f));
101
2 102 [s, forceWidth, f] = handleNumericPrecision(x, f);
103
2 104 if ~isempty(s)
2 105 return;
106 end
107 elseif ischar(f)
108 % Precision is specified as an ANSI C print format string.
109
110 % Explicit format strings should be explicitly padded
111 padColumnsWithSpace = false;
112
113 % Validate format string
114 k = strfind(f,'%');
115 if isempty(k)
116 error(message('MATLAB:num2str:fmtInvalid', f));
117 end
118 else
119 error(message('MATLAB:num2str:invalidSecondArgument'))
120 end
121
122 %-------------------------------------------------------------------------------
123 % Print numeric array as a string image of itself.
124
125 if isreal(x)
126 [raw, isLeft] = cellPrintf(f, x, false);
127 [m,n] = size(raw);
128 cols = cell(1,n);
129 widths = zeros(1,n);
130 for j = 1:n
131 if isLeft
132 cols{j} = char(raw(:,j));
133 else
134 cols{j} = strvrcat(raw(:,j));
135 end
136 widths(j) = size(cols{j}, 2);
137 end
138 else
139 forceWidth = 2*forceWidth + 2;
140 raw = cellPrintf(f, real(x), false);
141 imagRaw = cellPrintf(f, imag(x), true);
142 [m,n] = size(raw);
143 cols = cell(1,n);
144 widths = zeros(1,n);
145 for j = 1:n
146 cols{j} = [strvrcat(raw(:,j)) char(imagRaw(:,j))];
147 widths(j) = size(cols{j}, 2);
148 end
149 end
150
151 maxWidth = max([widths forceWidth]);
152 padWidths = maxWidth - widths;
153 padIndex = find(padWidths, 1);
154 while ~isempty(padIndex)
155 padWidth = padWidths(padIndex);
156 padCols = (padWidths==padWidth);
157 padWidths(padCols) = 0;
158 spaceCols = char(ones(m,padWidth)*' ');
159 cols(padCols) = strcat({spaceCols}, cols(padCols));
160 padIndex = find(padWidths, 1);
161 end
162
163 if padColumnsWithSpace
164 spaceCols = char(ones(m,1)*' ');
165 cols = strcat(cols, {spaceCols});
166 end
167
168 s = strtrim([cols{:}]);
169 end
Other subfunctions in this file are not included in this listing.