This is a static copy of a profile reportHome
ndgrid (606 calls, 6.108 sec)
Generated 05-Nov-2014 07:52:39 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/matlab/elmat/ndgrid.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 |
67 | varargout{i} = permute(x,[2:i ... | 1818 | 3.915 s | 64.1% |  |
66 | x = reshape(x(:,ones(1,prod(s)... | 1818 | 1.933 s | 31.6% |  |
58 | siz(i) = numel(varargin{i}); | 1818 | 0.050 s | 0.8% |  |
68 | end | 1818 | 0.040 s | 0.7% |  |
65 | s = siz; s(i) = []; % Remove i... | 1818 | 0.030 s | 0.5% |  |
All other lines | | | 0.140 s | 2.3% |  |
Totals | | | 6.108 s | 100% | |
Children (called functions)
No childrenCode Analyzer results
No Code Analyzer messages.Coverage results
[ Show coverage for parent directory ]
Total lines in function | 68 |
Non-code lines (comments, blank lines) | 43 |
Code lines (lines that can run) | 25 |
Code lines that did run | 16 |
Code lines that did not run | 9 |
Coverage (did run/can run) | 64.00 % |
Function listing
time calls line
1 function varargout = ndgrid(varargin)
2 %NDGRID Rectangular grid in N-D space
3 % [X1,X2,X3,...] = NDGRID(x1gv,x2gv,x3gv,...) replicates the grid vectors
4 % x1gv,x2gv,x3gv,... to produce the coordinates of a rectangular grid
5 % (X1,X2,X3,...). The i-th dimension of the output array Xi are copies
6 % of elements of the grid vector xigv. For example, the grid vector x1gv
7 % forms the rows of X1, the grid vector x2gv forms the columns of X2 etc.
8 %
9 % [X1,X2,...] = NDGRID(xgv) is equivalent to [X1,X2,...] = NDGRID(xgv,xgv,...).
10 % The dimension of the output is determined by the number of output
11 % arguments. X1 = NDGRID(xgv) degenerates to produce a 1-D grid represented
12 % by a 1-D array.
13 %
14 % The coordinate arrays are typically used for the evaluation of functions
15 % of several variables and for surface and volumetric plots.
16 %
17 % NDGRID and MESHGRID are similar, though NDGRID supports 1-D to N-D while
18 % MESHGRID is restricted to 2-D and 3-D. In 2-D and 3-D the coordinates
19 % output by each function are the same, the difference is the shape of the
20 % output arrays. For grid vectors x1gv, x2gv and x3gv of length M, N and P
21 % respectively, NDGRID(x1gv, x2gv) will output arrays of size M-by-N while
22 % MESHGRID(x1gv, x2gv) outputs arrays of size N-by-M. Similarly,
23 % NDGRID(x1gv, x2gv, x3gv) will output arrays of size M-by-N-by-P while
24 % MESHGRID(x1gv, x2gv, x3gv) outputs arrays of size N-by-M-by-P.
25 %
26 % Example: Evaluate the function x2*exp(-x1^2-x2^2-x^3) over the
27 % range -2 < x1 < 2, -2 < x2 < 2, -2 < x3 < 2,
28 %
29 % [x1,x2,x3] = ndgrid(-2:.2:2, -2:.25:2, -2:.16:2);
30 % z = x2 .* exp(-x1.^2 - x2.^2 - x3.^2);
31 % slice(x2,x1,x3,z,[-1.2 .8 2],2,[-2 -.2])
32 %
33 %
34 % Class support for inputs x1gv,x2gv,x3gv,...
35 % float: double, single
36 %
37 % See also MESHGRID, SLICE, INTERPN.
38
39 % Copyright 1984-2011 The MathWorks, Inc.
40 % $Revision: 1.17.4.3.2.1 $ $Date: 2011/07/01 16:38:00 $
41
0.02 606 42 if nargin==0 || (nargin > 1 && nargout > nargin)
43 error(message('MATLAB:ndgrid:NotEnoughInputs'));
44 end
0.01 606 45 if nargin==1
46 if nargout == 1 || nargout == 0
47 varargout{1} = varargin{1}(:);
48 return
49 else
50 varargin = repmat(varargin,[1 max(nargout,2)]);
51 end
52 end
606 53 nin = length(varargin);
0.01 606 54 nout = max(nargout,nin);
55
606 56 for i=length(varargin):-1:1,
1818 57 varargin{i} = full(varargin{i}); % Make sure everything is full
0.05 1818 58 siz(i) = numel(varargin{i});
0.01 1818 59 end
0.02 606 60 if length(siz)<nout, siz = [siz ones(1,nout-length(siz))]; end
61
0.01 606 62 varargout = cell(1,nout);
606 63 for i=1:nout,
0.01 1818 64 x = varargin{i}(:); % Extract and reshape as a vector.
0.03 1818 65 s = siz; s(i) = []; % Remove i-th dimension
1.93 1818 66 x = reshape(x(:,ones(1,prod(s))),[length(x) s]); % Expand x
3.92 1818 67 varargout{i} = permute(x,[2:i 1 i+1:nout]); % Permute to i'th dimension
0.04 1818 68 end