comparison scripts/plot/meshgrid.m @ 6813:75d99621f850

[project @ 2007-08-14 17:14:18 by jwe]
author jwe
date Tue, 14 Aug 2007 17:14:19 +0000
parents 34f96dd5441b
children 93c65f2a5668
comparison
equal deleted inserted replaced
6812:da3d4bb32f35 6813:75d99621f850
42 42
43 if (nargin < 2) 43 if (nargin < 2)
44 y = x; 44 y = x;
45 endif 45 endif
46 46
47 ## Use repmat to ensure that the result values have the same type as
48 ## the arguments.
49
47 if (nargout < 3) 50 if (nargout < 3)
48 if (isvector (x) && isvector (y)) 51 if (isvector (x) && isvector (y))
49 xx = ones (length (y), 1) * x(:).'; 52 xx = repmat (x(:).', length (y), 1);
50 yy = y(:) * ones (1, length (x)); 53 yy = repmat (y(:), 1, length (x));
51 else 54 else
52 error ("meshgrid: arguments must be vectors"); 55 error ("meshgrid: arguments must be vectors");
53 endif 56 endif
54 else 57 else
55 if (nargin < 3) 58 if (nargin < 3)
57 endif 60 endif
58 if (isvector (x) && isvector (y) && isvector (z)) 61 if (isvector (x) && isvector (y) && isvector (z))
59 lenx = length (x); 62 lenx = length (x);
60 leny = length (y); 63 leny = length (y);
61 lenz = length (z); 64 lenz = length (z);
62 xx = repmat (ones (leny, 1) * x(:).', [1, 1, lenz]); 65 xx = repmat (repmat (x(:).', leny, 1), [1, 1, lenz]);
63 yy = repmat (y(:) * ones (1, lenx), [1, 1, lenz]); 66 yy = repmat (repmat (y(:), 1, lenx), [1, 1, lenz]);
64 zz = reshape (repmat (z(:).', lenx*leny, 1)(:), leny, lenx, lenz); 67 zz = reshape (repmat (z(:).', lenx*leny, 1)(:), leny, lenx, lenz);
65 else 68 else
66 error ("meshgrid: arguments must be vectors"); 69 error ("meshgrid: arguments must be vectors");
67 endif 70 endif
68 endif 71 endif
69 72
70 endfunction 73 endfunction