This is a static copy of a profile reportHome
meshgrid (607 calls, 103.023 sec)
Generated 05-Nov-2014 07:52:39 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/matlab/elmat/meshgrid.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 |
73 | zz = zz(ones(ny,1),ones(nx,1),... | 417 | 34.137 s | 33.1% |  |
72 | yy = yy(:,ones(1,nx),ones(nz,1... | 417 | 33.576 s | 32.6% |  |
71 | xx = xx(ones(ny,1),:,ones(nz,1... | 417 | 33.046 s | 32.1% |  |
57 | xx = xx(ones(ny, 1),:); | 190 | 1.953 s | 1.9% |  |
58 | yy = yy(:,ones(1, nx)); | 190 | 0.250 s | 0.2% |  |
All other lines | | | 0.060 s | 0.1% |  |
Totals | | | 103.023 s | 100% | |
Children (called functions)
No childrenCode Analyzer results
Line number | Message |
50 | For better readability, use newline, semicolon, or comma before this statement. |
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 75 |
Non-code lines (comments, blank lines) | 45 |
Code lines (lines that can run) | 30 |
Code lines that did run | 24 |
Code lines that did not run | 6 |
Coverage (did run/can run) | 80.00 % |
Function listing
time calls line
1 function [xx,yy,zz] = meshgrid(x,y,z)
2 %MESHGRID Cartesian grid in 2-D/3-D space
3 % [X,Y] = MESHGRID(xgv,ygv) replicates the grid vectors xgv and ygv to
4 % produce the coordinates of a rectangular grid (X, Y). The grid vector
5 % xgv is replicated numel(ygv) times to form the columns of X. The grid
6 % vector ygv is replicated numel(xgv) times to form the rows of Y.
7 %
8 % [X,Y,Z] = MESHGRID(xgv,ygv,zgv) replicates the grid vectors xgv, ygv, zgv
9 % to produce the coordinates of a 3D rectangular grid (X, Y, Z). The grid
10 % vectors xgv,ygv,zgv form the columns of X, rows of Y, and pages of Z
11 % respectively. (X,Y,Z) are of size numel(ygv)-by-numel(xgv)-by(numel(zgv).
12 %
13 % [X,Y] = MESHGRID(gv) is equivalent to [X,Y] = MESHGRID(gv,gv).
14 % [X,Y,Z] = MESHGRID(gv) is equivalent to [X,Y,Z] = MESHGRID(gv,gv,gv).
15 %
16 % The coordinate arrays are typically used for the evaluation of functions
17 % of two or three variables and for surface and volumetric plots.
18 %
19 % MESHGRID and NDGRID are similar, though MESHGRID is restricted to 2-D
20 % and 3-D while NDGRID supports 1-D to N-D. In 2-D and 3-D the coordinates
21 % output by each function are the same, the difference is the shape of the
22 % output arrays. For grid vectors xgv, ygv and zgv of length M, N and P
23 % respectively, NDGRID(xgv, ygv) will output arrays of size M-by-N while
24 % MESHGRID(xgv, ygv) outputs arrays of size N-by-M. Similarly,
25 % NDGRID(xgv, ygv, zgv) will output arrays of size M-by-N-by-P while
26 % MESHGRID(xgv, ygv, zgv) outputs arrays of size N-by-M-by-P.
27 %
28 % Example: Evaluate the function x*exp(-x^2-y^2)
29 % over the range -2 < x < 2, -4 < y < 4,
30 %
31 % [X,Y] = meshgrid(-2:.2:2, -4:.4:4);
32 % Z = X .* exp(-X.^2 - Y.^2);
33 % surf(X,Y,Z)
34 %
35 %
36 % Class support for inputs xgv,ygv,zgv:
37 % float: double, single
38 %
39 % See also SURF, SLICE, NDGRID.
40
41 % J.N. Little 1-30-92, CBM 2-11-92.
42 % Copyright 1984-2011 The MathWorks, Inc.
43 % $Revision: 5.14.4.6.2.1 $ $Date: 2011/07/01 16:37:59 $
44
607 45 if nargin==0 || (nargin > 1 && nargout > nargin)
46 error(message('MATLAB:meshgrid:NotEnoughInputs'));
47 end
48
607 49 if nargin == 2 || (nargin == 1 && nargout < 3) % 2-D array case
0.01 190 50 if nargin == 1 y = x; end
190 51 if isempty(x) || isempty(y)
52 xx = zeros(0,0,class(x)); yy = zeros(0,0,class(y));
190 53 else
190 54 xx = full(x(:)).'; % Make sure x is a full row vector.
190 55 yy = full(y(:)); % Make sure y is a full column vector.
190 56 nx = length(xx); ny = length(yy);
1.95 190 57 xx = xx(ones(ny, 1),:);
0.25 190 58 yy = yy(:,ones(1, nx));
190 59 end
417 60 else % 3-D array case
417 61 if nargin == 1
62 y = x; z = x;
63 end
417 64 if isempty(x) || isempty(y) || isempty(z)
65 xx = zeros(0,0,class(x)); yy = zeros(0,0,class(y)); zz = zeros(0,0,class(z));
417 66 else
417 67 nx = numel(x); ny = numel(y); nz = numel(z);
0.01 417 68 xx = reshape(full(x(:)),[1 nx 1]); % Make sure x is a full row vector.
417 69 yy = reshape(full(y(:)),[ny 1 1]); % Make sure y is a full column vector.
417 70 zz = reshape(full(z(:)),[1 1 nz]); % Make sure z is a full page vector.
33.05 417 71 xx = xx(ones(ny,1),:,ones(nz,1));
33.58 417 72 yy = yy(:,ones(1,nx),ones(nz,1));
34.14 417 73 zz = zz(ones(ny,1),ones(nx,1),:);
0.01 417 74 end
417 75 end