]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/__axis_margin__.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / __axis_margin__.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_margin__ (@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_margin__ (axdata)
40
41   ## compute axis limits
42   minv = axdata(1);
43   maxv = axdata(2);
44   delv = (maxv-minv)/2;             # breadth of the plot
45   midv = (minv + maxv)/2;           # midpoint of the plot
46   axmid = [midv, midv];
47   axdel = [-0.1, 0.1];              # default plot width (if less than 2-d data)
48   
49   if (delv == 0)
50     if (midv != 0)
51       axdel = [-0.1*midv, 0.1*midv];
52     endif
53   else
54     ## they're at least one-dimensional
55     tolv = max(1e-8, 1e-8*abs(midv));
56     if (abs (delv) >= tolv)
57       axdel = 1.1*[-delv,delv];
58     endif
59   endif
60   
61   axvec = axmid + axdel;
62
63 endfunction