This is a static copy of a profile report

Home

sub2ind (5160919 calls, 951.776 sec)
Generated 05-Nov-2014 07:52:53 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/matlab/elmat/sub2ind.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
region_seg>get_curvaturesubfunction1876000
ml_findmainobjfunction404
strel>MakePeriodicLineStrelsubfunction808
strel>MakeLineStrelsubfunction404
ml_objs2imgfunction12115
ml_imgptspixelfunction3270960
ml_setimgptspixelfunction226
ppualfunction2
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
54
if (any(v(:) < 1)) || (any(...
10322244249.235 s26.2%
58
ndx = ndx + (v-1)*k(i);
10322244146.443 s15.4%
50
if ~isequal(s,size(v))
1032224468.224 s7.2%
44
k = [1 cumprod(siz(1:end-1))];
516091966.111 s6.9%
59
end
1032224450.069 s5.3%
All other lines  371.694 s39.1%
Totals  951.776 s100% 
Children (called functions)
No children
Code Analyzer results
No Code Analyzer messages.
Coverage results
[ Show coverage for parent directory ]
Total lines in function59
Non-code lines (comments, blank lines)35
Code lines (lines that can run)24
Code lines that did run17
Code lines that did not run7
Coverage (did run/can run)70.83 %
Function listing
   time   calls  line
1 function ndx = sub2ind(siz,varargin)
2 %SUB2IND Linear index from multiple subscripts.
3 % SUB2IND is used to determine the equivalent single index
4 % corresponding to a given set of subscript values.
5 %
6 % IND = SUB2IND(SIZ,I,J) returns the linear index equivalent to the
7 % row and column subscripts in the arrays I and J for a matrix of
8 % size SIZ.
9 %
10 % IND = SUB2IND(SIZ,I1,I2,...,IN) returns the linear index
11 % equivalent to the N subscripts in the arrays I1,I2,...,IN for an
12 % array of size SIZ.
13 %
14 % I1,I2,...,IN must have the same size, and IND will have the same size
15 % as I1,I2,...,IN. For an array A, if IND = SUB2IND(SIZE(A),I1,...,IN)),
16 % then A(IND(k))=A(I1(k),...,IN(k)) for all k.
17 %
18 % Class support for inputs I,J:
19 % float: double, single
20 %
21 % See also IND2SUB.
22
23 % Copyright 1984-2008 The MathWorks, Inc.
24 % $Revision: 1.14.4.9 $ $Date: 2010/08/23 23:08:15 $
25 %==============================================================================
26
19.68 5160919 27 siz = double(siz);
27.49 5160919 28 if length(siz)<2
29 error(message('MATLAB:sub2ind:InvalidSize'));
30 end
31
23.02 5160919 32 if length(siz) ~= nargin-1
33 %Adjust input
7.20 1876000 34 if length(siz)<nargin-1
35 %Adjust for trailing singleton dimensions
36 siz = [siz ones(1,nargin-length(siz)-1)];
5.07 1876000 37 else
38 %Adjust for linear indexing on last element
45.09 1876000 39 siz = [siz(1:nargin-2) prod(siz(nargin-1:end))];
6.79 1876000 40 end
8.47 1876000 41 end
42
43 %Compute linear indices
66.11 5160919 44 k = [1 cumprod(siz(1:end-1))];
20.46 5160919 45 ndx = 1;
48.14 5160919 46 s = size(varargin{1}); %For size comparison
28.00 5160919 47 for i = 1:length(siz),
46.92 10322244 48 v = varargin{i};
49 %%Input checking
68.22 10322244 50 if ~isequal(s,size(v))
51 %Verify sizes of subscripts
52 error(message('MATLAB:sub2ind:SubscriptVectorSize'));
53 end
249.23 10322244 54 if (any(v(:) < 1)) || (any(v(:) > siz(i)))
55 %Verify subscripts are within range
56 error(message('MATLAB:sub2ind:IndexOutOfRange'));
57 end
146.44 10322244 58 ndx = ndx + (v-1)*k(i);
50.07 10322244 59 end