This is a static copy of a profile reportHome
repmat (92879 calls, 7.913 sec)
Generated 05-Aug-2011 13:00:40 using cpu time.
function in file /usr/local/MATLAB/R2011a/toolbox/matlab/elmat/repmat.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 |
86 | B = A(:, ones(siz(2), 1)); | 210 | 1.454 s | 18.4% |  |
48 | if isscalar(A) | 92879 | 1.312 s | 16.6% |  |
49 | nelems = prod(double(siz)); | 92068 | 0.907 s | 11.5% |  |
63 | elseif all(siz > 0) % use g... | 32452 | 0.448 s | 5.7% |  |
46 | end | 92470 | 0.426 s | 5.4% |  |
All other lines | | | 3.366 s | 42.5% |  |
Totals | | | 7.913 s | 100% | |
Children (called functions)
No childrenCode Analyzer results
No Code Analyzer messages.Coverage results
[ Show coverage for parent directory ]
Total lines in function | 105 |
Non-code lines (comments, blank lines) | 42 |
Code lines (lines that can run) | 63 |
Code lines that did run | 37 |
Code lines that did not run | 26 |
Coverage (did run/can run) | 58.73 % |
Function listing
time calls line
1 function B = repmat(A,M,N)
2 %REPMAT Replicate and tile an array.
3 % B = repmat(A,M,N) creates a large matrix B consisting of an M-by-N
4 % tiling of copies of A. The size of B is [size(A,1)*M, size(A,2)*N].
5 % The statement repmat(A,N) creates an N-by-N tiling.
6 %
7 % B = REPMAT(A,[M N]) accomplishes the same result as repmat(A,M,N).
8 %
9 % B = REPMAT(A,[M N P ...]) tiles the array A to produce a
10 % multidimensional array B composed of copies of A. The size of B is
11 % [size(A,1)*M, size(A,2)*N, size(A,3)*P, ...].
12 %
13 % REPMAT(A,M,N) when A is a scalar is commonly used to produce an M-by-N
14 % matrix filled with A's value and having A's CLASS. For certain values,
15 % you may achieve the same results using other functions. Namely,
16 % REPMAT(NAN,M,N) is the same as NAN(M,N)
17 % REPMAT(SINGLE(INF),M,N) is the same as INF(M,N,'single')
18 % REPMAT(INT8(0),M,N) is the same as ZEROS(M,N,'int8')
19 % REPMAT(UINT32(1),M,N) is the same as ONES(M,N,'uint32')
20 % REPMAT(EPS,M,N) is the same as EPS(ONES(M,N))
21 %
22 % Example:
23 % repmat(magic(2), 2, 3)
24 % repmat(uint8(5), 2, 3)
25 %
26 % Class support for input A:
27 % float: double, single
28 %
29 % See also BSXFUN, MESHGRID, ONES, ZEROS, NAN, INF.
30
31 % Copyright 1984-2010 The MathWorks, Inc.
32 % $Revision: 1.17.4.17 $ $Date: 2010/08/23 23:08:12 $
33
0.10 92879 34 if nargin < 2
35 error(message('MATLAB:repmat:NotEnoughInputs'))
36 end
37
0.09 92879 38 if nargin == 2
409 39 if isscalar(M)
40 siz = [M M];
409 41 else
409 42 siz = M;
409 43 end
0.03 92470 44 else
0.31 92470 45 siz = [M N];
0.43 92470 46 end
47
1.31 92879 48 if isscalar(A)
0.91 92068 49 nelems = prod(double(siz));
0.38 92068 50 if nelems>0 && nelems < (2^31)-1 % use linear indexing for speed.
51 % Since B doesn't exist, the first statement creates a B with
52 % the right size and type. Then use scalar expansion to
53 % fill the array. Finally reshape to the specified size.
0.22 59616 54 B(nelems) = A;
0.05 59616 55 if ~isequal(B(1), B(nelems)) || ~(isnumeric(A) || islogical(A))
56 % if B(1) is the same as B(nelems), then the default value filled in for
57 % B(1:end-1) is already A, so we don't need to waste time redoing
58 % this operation. (This optimizes the case that A is a scalar zero of
59 % some class.)
0.03 4012 60 B(:) = A;
4012 61 end
0.42 59616 62 B = reshape(B,siz);
0.45 32452 63 elseif all(siz > 0) % use general indexing, cost of memory allocation dominates.
64 ind = num2cell(siz);
65 B(ind{:}) = A;
66 if ~isequal(B(1), B(ind{:})) || ~(isnumeric(A) || islogical(A))
67 B(:) = A;
68 end
0.02 32452 69 else
0.32 32452 70 B = A(ones(siz));
0.08 32452 71 end
811 72 elseif ismatrix(A) && numel(siz) == 2
811 73 [m,n] = size(A);
811 74 if (issparse(A))
75 [I, J, S] = find(A);
76 I = bsxfun(@plus, I(:), m*(0:siz(1)-1));
77 I = I(:); I = I(:,ones(1,siz(2)));
78 J = J(:); J = J(:,ones(1,siz(1)));
79 J = bsxfun(@plus, J(:), n*(0:siz(2)-1));
80 S = S(:); S = S(:,ones(1,prod(siz)));
81 B = sparse(I(:), J(:), S(:), siz(1)*m, siz(2)*n, prod(siz)*nnz(A));
811 82 else
811 83 if (m == 1 && siz(2) == 1)
0.25 593 84 B = A(ones(siz(1), 1), :);
218 85 elseif (n == 1 && siz(1) == 1)
1.45 210 86 B = A(:, ones(siz(2), 1));
8 87 else
8 88 mind = (1:m)';
8 89 nind = (1:n)';
8 90 mind = mind(:,ones(1,siz(1)));
8 91 nind = nind(:,ones(1,siz(2)));
8 92 B = A(mind,nind);
8 93 end
811 94 end
95 else
96 Asiz = size(A);
97 Asiz = [Asiz ones(1,length(siz)-length(Asiz))];
98 siz = [siz ones(1,length(Asiz)-length(siz))];
99 subs = cell(1,length(Asiz));
100 for i=length(Asiz):-1:1
101 ind = (1:Asiz(i))';
102 subs{i} = ind(:,ones(1,siz(i)));
103 end
104 B = A(subs{:});
105 end