This is a static copy of a profile reportHome
str2num (52 calls, 0.000 sec)
Generated 05-Aug-2011 13:00:29 using cpu time.
function in file /usr/local/MATLAB/R2011a/toolbox/matlab/strfun/str2num.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Lines where the most time was spent
No measurable time spent in this functionLine Number | Code | Calls | Total Time | % Time | Time Plot |
68 | return | 52 | 0 s | 0% |  |
67 | if isnumeric(x) | 52 | 0 s | 0% |  |
46 | [x,ok] = protected_conversion(... | 52 | 0 s | 0% |  |
45 | s(s==char(0)) = ' '; | 52 | 0 s | 0% |  |
43 | if m==1, | 52 | 0 s | 0% |  |
All other lines | | | 0 s | 0% |  |
Totals | | | 0 s | 0% | |
Children (called functions)
Function Name | Function Type | Calls | Total Time | % Time | Time Plot |
str2num>protected_conversion | subfunction | 52 | 0 s | 0% |  |
Self time (built-ins, overhead, etc.) | | | 0 s | 0% |  |
Totals | | | 0 s | 0% | |
Code Analyzer results
No Code Analyzer messages.Coverage results
[ Show coverage for parent directory ]
Total lines in function | 73 |
Non-code lines (comments, blank lines) | 34 |
Code lines (lines that can run) | 39 |
Code lines that did run | 8 |
Code lines that did not run | 31 |
Coverage (did run/can run) | 20.51 % |
Function listing
time calls line
1 function [x,ok] = str2num(s)
2 %STR2NUM Convert string matrix to numeric array.
3 % X = STR2NUM(S) converts a character array representation of a matrix of
4 % numbers to a numeric matrix. For example,
5 %
6 % S = ['1 2' str2num(S) => [1 2;3 4]
7 % '3 4']
8 %
9 % The numbers in the string matrix S should be ASCII character
10 % representations of a numeric values. Each number may contain digits,
11 % a decimal point, a leading + or - sign, an 'e' or 'd' preceding a
12 % power of 10 scale factor, and an 'i' or 'j' for a complex unit.
13 %
14 % If the string S does not represent a valid number or matrix,
15 % STR2NUM(S) returns the empty matrix. [X,OK]=STR2NUM(S) will
16 % return OK=0 if the conversion failed.
17 %
18 % CAUTION: STR2NUM uses EVAL to convert the input argument, so side
19 % effects can occur if the string contains calls to functions. Use
20 % STR2DOUBLE to avoid such side effects or when S contains a single
21 % number.
22 %
23 % Also spaces can be significant. For instance, str2num('1+2i') and
24 % str2num('1 + 2i') produce x = 1+2i while str2num('1 +2i') produces
25 % x = [1 2i]. These problems are also avoided when you use STR2DOUBLE.
26 %
27 % See also STR2DOUBLE, NUM2STR, HEX2NUM, CHAR.
28
29 % Copyright 1984-2007 The MathWorks, Inc.
30 % $Revision: 5.31.4.9 $ $Date: 2010/08/23 23:13:25 $
31
52 32 if ~ischar(s) || ndims(s)>2
33 error(message('MATLAB:str2num:InvalidArgument'))
34 end
35
52 36 if isempty(s)
37 x = [];
38 ok=false;
39 return
40 end
41
52 42 [m,n] = size(s);
52 43 if m==1,
44 % Replace any char(0) characters with spaces
52 45 s(s==char(0)) = ' ';
52 46 [x,ok] = protected_conversion(['[' s ']']); % Always add brackets
47 else
48 semi = ';';
49 space = ' ';
50 if ~any(any(s == '[' | s == ']')), % String does not contain brackets
51 o = ones(m-1,1);
52 s = [['[';space(o)] s [semi(o) space(o);' ]']]';
53 elseif ~any(any(s(1:m-1,:) == semi)), % No ;'s in non-last rows
54 s = [s,[semi(ones(m-1,1));space]]';
55 else % Put ;'s where appropriate
56 spost = space(ones(m,1));
57 for i = 1:m-1,
58 last = find(s(i,:) ~= space,1,'last');
59 if s(i,n-last+1) ~= semi,
60 spost(i) = semi;
61 end
62 end
63 s = [s,spost]';
64 end
65 [x,ok] = protected_conversion(s);
66 end
52 67 if isnumeric(x)
52 68 return
69 end
70 if ischar(x) || iscell(x)
71 x = [];
72 ok = false;
73 end
Other subfunctions in this file are not included in this listing.