diff 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
line wrap: on
line diff
--- a/scripts/plot/meshgrid.m
+++ b/scripts/plot/meshgrid.m
@@ -44,10 +44,13 @@
     y = x;
   endif
 
+  ## Use repmat to ensure that the result values have the same type as
+  ## the arguments.
+
   if (nargout < 3)
     if (isvector (x) && isvector (y))
-      xx = ones (length (y), 1) * x(:).';
-      yy = y(:) * ones (1, length (x));
+      xx = repmat (x(:).', length (y), 1);
+      yy = repmat (y(:), 1, length (x));
     else
       error ("meshgrid: arguments must be vectors");
     endif
@@ -59,11 +62,11 @@
        lenx = length (x);
        leny = length (y);
        lenz = length (z);
-       xx = repmat (ones (leny, 1) * x(:).', [1, 1, lenz]);
-       yy = repmat (y(:) * ones (1, lenx), [1, 1, lenz]);
+       xx = repmat (repmat (x(:).', leny, 1), [1, 1, lenz]);
+       yy = repmat (repmat (y(:), 1, lenx), [1, 1, lenz]);
        zz = reshape (repmat (z(:).', lenx*leny, 1)(:), leny, lenx, lenz);
     else
-       error ("meshgrid: arguments must be vectors");
+      error ("meshgrid: arguments must be vectors");
     endif
   endif