]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/__axis_limits__.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / __axis_limits__.m
1 ## Copyright (C) 1998, 2000, 2004, 2005, 2007
2 ##               Auburn University.  All rights reserved.
3 ##
4 ##
5 ## This program is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## This program is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} __axis_limits__ (@var{axdata})
21 ## Determine axis limits for 2-D data (column vectors); leaves a 10%
22 ## margin around the plots.
23 ## Inserts margins of +/- 0.1 if data is one-dimensional 
24 ## (or a single point).
25 ##
26 ## @strong{Input}
27 ## @table @var
28 ## @item axdata
29 ## @var{n} by 2 matrix of data [@var{x}, @var{y}].
30 ## @end table
31 ##
32 ## @strong{Output}
33 ## @table @var
34 ## @item axvec
35 ## Vector of axis limits appropriate for call to @command{axis} function.
36 ## @end table
37 ## @end deftypefn
38
39 function axvec = __axis_limits__ (axdata)
40
41   if (nargin < 1 || isempty (axdata))
42     axdata = 0;
43   endif
44
45   ## compute axis limits
46   minv = min (axdata);
47   maxv = max (axdata);
48   delv = (maxv-minv)/2;             # breadth of the plot
49   midv = (minv + maxv)/2;           # midpoint of the plot
50   axmid = [midv(1), midv(1), midv(2), midv(2)];
51   axdel = [-0.1, 0.1, -0.1, 0.1];   # default plot width (if less than 2-d data)
52   if (max (delv) == 0)
53     if (midv(1) != 0)
54       axdel(1:2) = [-0.1*midv(1), 0.1*midv(1)];
55     endif
56     if (midv(2) != 0)
57       axdel(3:4) = [-0.1*midv(2), 0.1*midv(2)];
58     endif
59   else
60     ## they're at least one-dimensional
61     tolv = max(1e-8, 1e-8*abs(midv));
62     if (abs (delv(1)) >= tolv(1))
63       axdel(1:2) = 1.1*[-delv(1),delv(1)];
64     endif
65     if (abs (delv(2)) >= tolv(2))
66       axdel(3:4) = 1.1*[-delv(2),delv(2)];
67     endif
68   endif
69   axvec = axmid + axdel;
70
71 endfunction