changeset 19566:009191dbc76d

quiver: fix initialization error when called with zeros (bug #43686) * __quiver__.m: initialize uu, vv and ww, and compute arrows length first.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Thu, 27 Nov 2014 21:49:55 +0100
parents cc7931e8953d
children 9ef286208da1
files scripts/plot/draw/private/__quiver__.m
diffstat 1 files changed, 18 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/draw/private/__quiver__.m
+++ b/scripts/plot/draw/private/__quiver__.m
@@ -112,8 +112,16 @@
   ## Normalize 0.20 to 1/3 for plotting
   arrowsize /= 0.20 * 3;
 
-  if (autoscale && numel (u) > 1)
-    ## Scale the arrows to fit in the grid
+  ## Scale the arrows to fit in the grid
+  uu = u;
+  vv = v;
+  if (is3d)
+    ww = w;
+    len = max (sqrt (u(:).^2 + v(:).^2 + w(:).^2));
+  else
+    len = max (sqrt (u(:).^2 + v(:).^2));      
+  endif
+  if (len > 0 && autoscale && numel (u) > 1)
     if (isvector (x))
       nx = ny = sqrt (length (x));
     else
@@ -123,29 +131,19 @@
     dy = (max (y(:)) - min (y(:))) / ny;
     if (is3d)
       dz = (max (z(:)) - min (z(:))) / max (nx, ny);
-      len = max (sqrt (u(:).^2 + v(:).^2 + w(:).^2));
     else
       dz = 0;
-      len = max (sqrt (u(:).^2 + v(:).^2));
     endif
-    if (len > 0)
-      sd = sqrt (dx.^2 + dy.^2 + dz.^2) / len;
-      if (sd != 0)
-        s = autoscale * sd;
-      else  # special case of identical points with multiple vectors
-        s = autoscale;
-      endif
-      uu = s * u;
-      vv = s * v;
-      if (is3d)
-        ww = s * w;
-      endif
+    sd = sqrt (dx.^2 + dy.^2 + dz.^2) / len;
+    if (sd != 0)
+      s = autoscale * sd;
+    else  # special case of identical points with multiple vectors
+      s = autoscale;
     endif
-  else
-    uu = u;
-    vv = v;
+    uu = s * u;
+    vv = s * v;
     if (is3d)
-      ww = w;
+      ww = s * w;
     endif
   endif