octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

stem3 function


From: John W. Eaton
Subject: stem3 function
Date: Thu, 29 Nov 2007 16:10:40 -0500

On 29-Nov-2007, David Bateman wrote:

| Here is a patch that adds the stem3 function, by generalizing the stem
| function to 3D and using the resulting function for both stem and stem3.

I checked them in with the following additional changes.  Please let
me know if these changes look OK, especially the change to move the
call to print_usage from __stem__ to stem and stem3.

Thanks,

jwe


Index: scripts/plot/__stem__.m
===================================================================
RCS file: /cvs/octave/scripts/plot/__stem__.m,v
retrieving revision 1.1
diff -u -u -w -r1.1 __stem__.m
--- scripts/plot/__stem__.m     29 Nov 2007 20:50:24 -0000      1.1
+++ scripts/plot/__stem__.m     29 Nov 2007 21:09:31 -0000
@@ -23,12 +23,14 @@
 
 function h = __stem__ (have_z, varargin)
 
-  [ax, varargin, nargin] = __plt_get_axis_arg__ ("stem", varargin{:});
-
-  if (nargin < 1 || nargin > 4)
-    print_usage ();
+  if (have_z)
+    caller = "stem3";
+  else
+    caller = "stem";
   endif
 
+  [ax, varargin, nargin] = __plt_get_axis_arg__ (caller, varargin{:});
+
   [x, y, z, dofill, lc, ls, mc, ms] = check_stem_arg (have_z, varargin{:});
 
   if (dofill)
@@ -81,6 +83,12 @@
 
 function [x, y, z, dofill, lc, ls, mc, ms] = check_stem_arg (have_z, varargin)
 
+  if (have_z)
+    caller = "stem3";
+  else
+    caller = "stem";
+  endif
+
   ## set specifiers to default values
   [lc, ls, mc, ms] = set_default_values ();
   dofill = 0;
@@ -115,7 +123,7 @@
        dofill = 1;
       else
        ## parse the linespec
-       [lc, ls, mc, ms] = stem_line_spec (varargin{2});
+       [lc, ls, mc, ms] = stem_line_spec (caller, varargin{2});
       endif
       if (have_z)
        z = varargin{1};
@@ -156,7 +164,7 @@
        fill_2 = 1; # be sure, no second "fill" is in the arguments
       else
        ## must be a linespec
-       [lc, ls, mc, ms] = stem_line_spec (varargin{2});
+       [lc, ls, mc, ms] = stem_line_spec (caller, varargin{2});
        linespec_2 = 1;
       endif
       if (have_z)
@@ -168,7 +176,7 @@
        if (isvector (y))
          x = 1:length(y);
        elseif (ismatrix (y))
-         x = 1:size(y,1);
+         x = 1:rows (y);
        else
          error ("stem: Y must be a matrix");
        endif # in each case, x & y will be defined
@@ -191,21 +199,21 @@
       endif
     endif # if ischar(varargin{2})
     if (! have_z)
-      ## varargin{3} must be char...
-      ## check for "fill" ..
-      if (strcmp ("fill", varargin{3}) & fill_2)
-       error ("stem:check_stem_arg: duplicate fill argument");
-      elseif (strcmp("fill", varargin{3}) & linespec_2)
+      ## varargin{3} must be char
+      ## check for "fill"
+      if (strcmp ("fill", varargin{3}) && fill_2)
+       error ("stem: duplicate fill argument");
+      elseif (strcmp("fill", varargin{3}) && linespec_2)
        ## must be "fill"
        dofill = 1;
        fill_2 = 1;
-      elseif (strcmp ("fill", varargin{3}) & ! linespec_2)
+      elseif (strcmp ("fill", varargin{3}) && ! linespec_2)
        ## must be "fill"
        dofill = 1;
        fill_2 = 1;
       elseif (! linespec_2)
        ## must be linespec
-       [lc, ls, mc, ms] = stem_line_spec (varargin{3});
+       [lc, ls, mc, ms] = stem_line_spec (caller, varargin{3});
        linespec_2 = 1;
       endif
     endif
@@ -221,7 +229,7 @@
       x = varargin{1};
       y = varargin{2};
       if (! (ismatrix (x) && ismatrix (y)))
-       error ("X and Y must be matrices");
+       error ("stem: X and Y must be matrices");
       endif
     endif
 
@@ -231,21 +239,21 @@
        fill_2 = 1; # be sure, no second "fill" is in the arguments
       else
        ## must be a linespec
-       [lc, ls, mc, ms] = stem_line_spec (varargin{3});
+       [lc, ls, mc, ms] = stem_line_spec (caller, varargin{3});
        linespec_2 = 1;
       endif
     endif
 
     ## check for "fill" ..
-    if (strcmp ("fill", varargin{4}) & fill_2)
-      error ("stem:check_stem_arg: duplicate fill argument");
-    elseif (strcmp ("fill", varargin{4}) & linespec_2)
+    if (strcmp ("fill", varargin{4}) && fill_2)
+      error ("%s: duplicate fill argument", caller);
+    elseif (strcmp ("fill", varargin{4}) && linespec_2)
       ## must be "fill"
       dofill = 1;
       fill_2 = 1;
-    elseif (! strcmp ("fill", varargin{4}) & ! linespec_2)
+    elseif (! strcmp ("fill", varargin{4}) && ! linespec_2)
       ## must be linespec
-      [lc, ls, mc, ms] = stem_line_spec (varargin{4});
+      [lc, ls, mc, ms] = stem_line_spec (caller, varargin{4});
       linespec_2 = 1;
     endif
   elseif (nargin == 6 && have_z)
@@ -261,33 +269,32 @@
       fill_2 = 1; # be sure, no second "fill" is in the arguments
     else
       ## must be a linespec
-      [lc, ls, mc, ms] = stem_line_spec (varargin{4});
+      [lc, ls, mc, ms] = stem_line_spec (caller, varargin{4});
       linespec_2 = 1;
     endif
 
     ## check for "fill" ..
-    if (strcmp ("fill", varargin{5}) & fill_2)
-      error ("stem3:check_stem_arg: duplicate fill argument");
-    elseif (strcmp ("fill", varargin{5}) & linespec_2)
+    if (strcmp ("fill", varargin{5}) && fill_2)
+      error ("stem3: duplicate fill argument");
+    elseif (strcmp ("fill", varargin{5}) && linespec_2)
       ## must be "fill"
       dofill = 1;
       fill_2 = 1;
-    elseif (! strcmp ("fill", varargin{5}) & ! linespec_2)
+    elseif (! strcmp ("fill", varargin{5}) && ! linespec_2)
       ## must be linespec
-      [lc, ls, mc, ms] = stem_line_spec (varargin{5});
+      [lc, ls, mc, ms] = stem_line_spec (caller, varargin{5});
       linespec_2 = 1;
     endif
-  elseif (have_z)
-    error ("stem3: incorrect number of arguments");
   else
-    error ("stem: incorrect number of arguments");
+    error ("%s: incorrect number of arguments", caller);
   endif
 
 endfunction
 
-function [lc, ls, mc, ms] = stem_line_spec (str)
+function [lc, ls, mc, ms] = stem_line_spec (caller, str)
   if (! ischar (str))
-    error ("stem:stem_line_spec: wrong argument type, must be \"fill\" or a 
string of specifiers");
+    error ("%s: expecting argument to be \"fill\" or a string of specifiers",
+          caller);
   endif
   [lc, ls, mc, ms] = set_default_values ();
   ## Parse the line specifier string.
Index: scripts/plot/stem.m
===================================================================
RCS file: /cvs/octave/scripts/plot/stem.m,v
retrieving revision 1.14
diff -u -u -w -r1.14 stem.m
--- scripts/plot/stem.m 29 Nov 2007 20:50:24 -0000      1.14
+++ scripts/plot/stem.m 29 Nov 2007 21:09:31 -0000
@@ -94,6 +94,10 @@
 
 function h = stem (varargin)
 
+  if (nargin < 1 || nargin > 3)
+    print_usage ();
+  endif
+
   tmp = __stem__ (false, varargin{:});
 
   if (nargout > 0)
Index: scripts/plot/stem3.m
===================================================================
RCS file: /cvs/octave/scripts/plot/stem3.m,v
retrieving revision 1.1
diff -u -u -w -r1.1 stem3.m
--- scripts/plot/stem3.m        29 Nov 2007 20:50:24 -0000      1.1
+++ scripts/plot/stem3.m        29 Nov 2007 21:09:31 -0000
@@ -37,6 +37,10 @@
 
 function h = stem3 (varargin)
 
+  if (nargin < 3 || nargin > 4)
+    print_usage ();
+  endif
+
   tmp = __stem__ (true, varargin{:});
 
   if (nargout > 0)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]