changeset 11344:cac58372d547

Make view more compatible
author Kai Habel <kai.habel@gmx.de>
date Sun, 12 Dec 2010 16:44:29 +0100
parents 5e5c513ea4c5
children 488f07b65b1d
files scripts/ChangeLog scripts/plot/view.m
diffstat 2 files changed, 47 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Fri Dec 10 19:59:25 2010 -0500
+++ b/scripts/ChangeLog	Sun Dec 12 16:44:29 2010 +0100
@@ -1,3 +1,8 @@
+2010-12-12  Kai Habel  <kai.habel@gmx.de>
+
+	* plot/view.m: Make view more compatible. Allow cartesian
+	coordinates and axes handle arguments.
+
 2010-12-10  Ben Abbott  <bpabbott@mac.com>
 
 	* io/strread.m: Don't require space between format specifiers.
--- a/scripts/plot/view.m	Fri Dec 10 19:59:25 2010 -0500
+++ b/scripts/plot/view.m	Sun Dec 12 16:44:29 2010 +0100
@@ -18,39 +18,70 @@
 
 ## -*- texinfo -*-
 ## @deftypefn  {Function File} {} view (@var{azimuth}, @var{elevation})
+## @deftypefnx  {Function File} {} view ([@var{azimuth}, @var{elevation}])
+## @deftypefnx  {Function File} {} view ([@var{x}, @var{y}, @var{z}])
 ## @deftypefnx {Function File} {} view (@var{dims})
+## @deftypefnx {Function File} {} view (@var{ax}, @dots{})
 ## @deftypefnx {Function File} {[@var{azimuth}, @var{elevation}] =} view ()
-## Set or get the viewpoint for the current axes.
+## Set or get the viewpoint for the current axes. The parameters 
+## @var{azimuth} and @var{elevation} can be given as two arguments or as
+## 2-element vector. 
+## The viewpoint can also be given with cartesian coordinates @var{x}, 
+## @var{y}, and @var{z}. 
+## The call @code{view (2)} sets the viewpoint to @var{azimuth} = 0
+## and @var{elevation} = 90, which is default for 2d graphs.
+## The call @code{view (3)} sets the viewpoint to @var{azimuth} = -37.5
+## and @var{elevation} = 30, which is default for 3d graphs.
+## If @var{ax} is given, the viewpoint is set for this axes, otherwise
+## it is set for the current axes.
 ## @end deftypefn
 
 ## Author: jwe
 
-function [azimuth, elevation] = view (x, y, z)
+function [azimuth, elevation] = view (varargin)
 
-  if (nargin < 4)
+  if (nargin < 3)
+
     if (nargin == 0)
       tmp = get (gca (), "view");
       az = tmp(1);
       el = tmp(2);
-    elseif (nargin == 1)
-      if (x == 2)
+    else
+      ax = varargin{1};
+      if (ishandle (ax) && strcmp (get (ax, "type"), "axes"))
+        args = varargin{2:end};
+      else
+        ax = gca;
+        args = varargin;
+      endif
+    endif
+    
+    if (nargin == 1)
+      x = args{1};
+      if (length (x) == 2)
+        az = x(1);
+        el = x(2);
+      elseif (length (x) == 3)
+        [az, el] = cart2sph (x(1), x(2), x(3));
+        az *= 180/pi;
+        az += 90;
+        el *= 180/pi;
+      elseif (x == 2)
         az = 0;
         el = 90;
       elseif (x == 3)
         az = -37.5;
         el = 30;
       else
-        error ("view: expecting single argument to be 2 or 3");
+        print_usage ();
       endif
     elseif (nargin == 2)
-      az = x;
-      el = y;
-    elseif (nargin == 3)
-      error ("view: view (x, y, z) not implemented");
+      az = args{1};
+      el = args{2};
     endif
 
     if (nargin > 0)
-      set (gca (), "view", [az, el]);
+      set (ax, "view", [az, el]);
     endif
 
     if (nargout == 1)