changeset 5910:101d966c8d6b

[project @ 2006-07-28 03:40:22 by jwe]
author jwe
date Fri, 28 Jul 2006 03:40:22 +0000
parents a6a2423a9c25
children a65b51ed388c
files scripts/ChangeLog scripts/plot/plot3.m
diffstat 2 files changed, 75 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog
+++ b/scripts/ChangeLog
@@ -1,3 +1,8 @@
+2006-07-27  Jim Peterson  <jpeterson@annapmicro.com>
+
+	* plot/plot3.m: Accept one complex or one real and one complex
+	argument and plot real and imaginary components for y and z.
+
 2006-07-27  John W. Eaton  <jwe@octave.org>
 
 	* testfun/test.m: Call fflush after each block of calls to
--- a/scripts/plot/plot3.m
+++ b/scripts/plot/plot3.m
@@ -18,7 +18,7 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} plot (@var{args})
+## @deftypefn {Function File} {} plot3 (@var{args})
 ##
 ## This function produces three-dimensional plots.  Many different
 ## combinations of arguments are possible.  The simplest form is
@@ -35,6 +35,24 @@
 ## line. No attempt is made to transpose the arguments to make the
 ## number of rows match.
 ##
+## Additionally, only two arguments can be given as
+##
+## @example
+## plot3 (@var{x}, @var{c})
+## @end example
+##
+## where the real and imaginary parts of the second argument are used as
+## the @var{y} and @var{z} coordinates, respectively.
+##
+## If only one argument is given, as
+##
+## @example
+## plot3 (@var{c})
+## @end example
+##
+## the real and imaginary parts of the argument are used as the @var{y}
+## and @var{z} values, and they are plotted versus their index.
+##
 ## To save a plot, in one of several image formats such as PostScript
 ## or PNG, use the @code{print} command.
 ##
@@ -118,8 +136,15 @@
 ## @end example
 ## 
 ## @noindent
-## where each set of three arguments are treated as seperate lines or
-## sets of lines in three dimensions.
+## where each set of three arguments is treated as a seperate line or
+## set of lines in three dimensions.
+##
+## To plot multiple one- or two-argument groups, separate each group with an
+## empty format string, as
+##
+## @example
+## plot3 (@var{x1}, @var{c1}, '', @var{c2}, '', @dots{})
+## @end example
 ##
 ## An example of the use of plot3 is
 ##
@@ -127,6 +152,7 @@
 ## @group
 ##    z = [0:0.05:5];
 ##    plot3(cos(2*pi*z), sin(2*pi*z), z, ";helix;");
+##    plot3(z, exp(2i*pi*z), ";complex sinusoid;");
 ## @end group
 ## @end example
 ##
@@ -153,11 +179,29 @@
       
       if (ischar (new))
 	if (! z_set)
-	  error ("plot3: needs x, y, z");
+	  if (! y_set)
+	    if (! x_set)
+	      error ("plot3: needs x, [ y, [ z ] ]");
+	    else
+	      z = imag (x);
+	      y = real (x);
+	      y_set = 1;
+	      z_set = 1;
+	      if (rows(x) > 1)
+	        x = repmat ((1:rows(x))', 1, columns(x));
+	      else
+	        x = 1:columns(x);
+	      endif
+	    endif
+	  else
+	    z = imag (y);
+	    y = real (y);
+	    z_set = 1;
+	  endif
 	endif
 	fmt = __pltopt__ ("plot3", new);
-	__plt3__(x, y, z, fmt);
-	hold on;
+	__plt3__ (x, y, z, fmt);
+	hold ("on");
 	x_set = 0;
 	y_set = 0;
 	z_set = 0;
@@ -172,7 +216,7 @@
 	z_set = 1;
       else
 	__plt3__ (x, y, z, "");
-	hold on;
+	hold ("on");
 	x = new;
 	y_set = 0;
 	z_set = 0;
@@ -182,16 +226,31 @@
     
     ## Handle last plot.
     
-    if  (z_set)
+    if (x_set)
+      if (y_set)
+        if (! z_set)
+          z = imag (y);
+          y = real (y);
+          z_set = 1;
+        endif
+      else
+        z = imag (x);
+        y = real (x);
+        y_set = 1;
+        z_set = 1;
+        if (rows (x) > 1)
+          x = repmat ((1:rows (x))', 1, columns(x));
+        else
+          x = 1:columns(x);
+        endif
+      endif
       __plt3__ (x, y, z, "");
-    elseif (x_set)
-      error ("plot3: needs x, y, z");
     endif
     
   unwind_protect_cleanup
     
     if (! hold_state)
-      hold off;
+      hold ("off");
     endif
     
   end_unwind_protect