This is a static copy of a profile report

Home

cell2mat (1 call, 0.000 sec)
Generated 05-Nov-2014 07:53:56 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/matlab/datatypes/cell2mat.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
spvalfunction1
Lines where the most time was spent
No measurable time spent in this function

Line NumberCodeCallsTotal Time% TimeTime Plot
89
return
10 s0%
79
m = cat(1,m{:});
10 s0%
77
end
10 s0%
76
m{n} = cat(2,c{n,:});
10 s0%
75
for n=1:rows
10 s0%
All other lines  0 s0%
Totals  0 s0% 
Children (called functions)
No children
Code Analyzer results
Line numberMessage
116{ A{I} } can usually be replaced by A(I) or A(I)', which can be much faster.
Coverage results
[ Show coverage for parent directory ]
Total lines in function126
Non-code lines (comments, blank lines)59
Code lines (lines that can run)67
Code lines that did run21
Code lines that did not run46
Coverage (did run/can run)31.34 %
Function listing
   time   calls  line
1 function m = cell2mat(c)
2 %CELL2MAT Convert the contents of a cell array into a single matrix.
3 % M = CELL2MAT(C) converts a multidimensional cell array with contents of
4 % the same data type into a single matrix. The contents of C must be able
5 % to concatenate into a hyperrectangle. Moreover, for each pair of
6 % neighboring cells, the dimensions of the cell's contents must match,
7 % excluding the dimension in which the cells are neighbors. This constraint
8 % must hold true for neighboring cells along all of the cell array's
9 % dimensions.
10 %
11 % The dimensionality of M, i.e. the number of dimensions of M, will match
12 % the highest dimensionality contained in the cell array.
13 %
14 % CELL2MAT is not supported for cell arrays containing cell arrays or
15 % objects.
16 %
17 % Example:
18 % C = {[1] [2 3 4]; [5; 9] [6 7 8; 10 11 12]};
19 % M = cell2mat(C)
20 %
21 % See also MAT2CELL, NUM2CELL
22
23 % Copyright 1984-2010 The MathWorks, Inc.
24 % $Revision: 1.10.4.10 $ $Date: 2011/01/28 18:50:42 $
25
26 % Error out if there is no input argument
1 27 if nargin==0
28 error(message('MATLAB:cell2mat:NoInputs'));
29 end
30 % short circuit for simplest case
1 31 elements = numel(c);
1 32 if elements == 0
33 m = [];
34 return
35 end
1 36 if elements == 1
37 if isnumeric(c{1}) || ischar(c{1}) || islogical(c{1}) || isstruct(c{1})
38 m = c{1};
39 return
40 end
41 end
42 % Error out if cell array contains mixed data types
1 43 cellclass = class(c{1});
1 44 ciscellclass = cellfun('isclass',c,cellclass);
1 45 if ~all(ciscellclass(:))
46 error(message('MATLAB:cell2mat:MixedDataTypes'));
47 end
48
49 % Error out if cell array contains any cell arrays or objects
1 50 ciscell = iscell(c{1});
1 51 cisobj = isobject(c{1});
1 52 if cisobj || ciscell
53 error(message('MATLAB:cell2mat:UnsupportedCellContent'));
54 end
55
56 % If cell array of structures, make sure the field names are all the same
1 57 if isstruct(c{1})
58 cfields = cell(elements,1);
59 for n=1:elements
60 cfields{n} = fieldnames(c{n});
61 end
62 % Perform the actual field name equality test
63 if ~isequal(cfields{:})
64 error(message('MATLAB:cell2mat:InconsistentFieldNames'));
65 end
66 end
67
68 % If cell array is 2-D, execute 2-D code for speed efficiency
1 69 if ndims(c) == 2
1 70 rows = size(c,1);
1 71 cols = size(c,2);
1 72 if (rows < cols)
1 73 m = cell(rows,1);
74 % Concatenate one dim first
1 75 for n=1:rows
1 76 m{n} = cat(2,c{n,:});
1 77 end
78 % Now concatenate the single column of cells into a matrix
1 79 m = cat(1,m{:});
80 else
81 m = cell(1, cols);
82 % Concatenate one dim first
83 for n=1:cols
84 m{n} = cat(1,c{:,n});
85 end
86 % Now concatenate the single column of cells into a matrix
87 m = cat(2,m{:});
88 end
1 89 return
90 end
91
92 csize = size(c);
93 % Treat 3+ dimension arrays
94
95 % Construct the matrix by concatenating each dimension of the cell array into
96 % a temporary cell array, CT
97 % The exterior loop iterates one time less than the number of dimensions,
98 % and the final dimension (dimension 1) concatenation occurs after the loops
99
100 % Loop through the cell array dimensions in reverse order to perform the
101 % sequential concatenations
102 for cdim=(length(csize)-1):-1:1
103 % Pre-calculated outside the next loop for efficiency
104 ct = cell([csize(1:cdim) 1]);
105 cts = size(ct);
106 ctsl = length(cts);
107 mref = {};
108
109 % Concatenate the dimension, (CDIM+1), at each element in the temporary cell
110 % array, CT
111 for mind=1:prod(cts)
112 [mref{1:ctsl}] = ind2sub(cts,mind);
113 % Treat a size [N 1] array as size [N], since this is how the indices
114 % are found to calculate CT
115 if ctsl==2 && cts(2)==1
116 mref = {mref{1}};
117 end
118 % Perform the concatenation along the (CDIM+1) dimension
119 ct{mref{:}} = cat(cdim+1,c{mref{:},:});
120 end
121 % Replace M with the new temporarily concatenated cell array, CT
122 c = ct;
123 end
124
125 % Finally, concatenate the final rows of cells into a matrix
126 m = cat(1,c{:});