home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / control / axis2dlim.m < prev    next >
Text File  |  1999-03-05  |  2KB  |  58 lines

  1. # Copyright (C) 1998 A. Scottedward Hodel 
  2. #
  3. # This file is part of Octave. 
  4. #
  5. # Octave is free software; you can redistribute it and/or modify it 
  6. # under the terms of the GNU General Public License as published by the 
  7. # Free Software Foundation; either version 2, or (at your option) any 
  8. # later version. 
  9. # Octave is distributed in the hope that it will be useful, but WITHOUT 
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  11. # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
  12. # for more details.
  13. # You should have received a copy of the GNU General Public License 
  14. # along with Octave; see the file COPYING.  If not, write to the Free 
  15. # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  16.  
  17. function axvec = axis2dlim(axdata)
  18. # function axvec = axis2dlim(axdata)
  19. # determine axis limits for 2-d data; leaves a 10% margin around the plots.
  20. # puts in margins of +/- 0.1 if data is one dimensional (or a single point)
  21. # inputs:
  22. #   axdata: nx2 matrix of data [x,y]
  23. # outputs:
  24. #   vector of axis limits appropriate for call to axis() function
  25.  
  26.   if(isempty(axdata))
  27.     axdata = 0;
  28.   endif
  29.  
  30.   # compute axis limits
  31.   minv = min(axdata);
  32.   maxv = max(axdata);
  33.   delv = (maxv-minv)/2;      # breadth of the plot
  34.   midv = (minv + maxv)/2;    # midpoint of the plot
  35.   axmid = [midv(1), midv(1), midv(2), midv(2)];
  36.   axdel = [-0.1, 0.1,-0.1,0.1];   # default plot width (if less than 2-d data)
  37.   if(max(delv) == 0)
  38.     if(midv(1) != 0)
  39.       axdel(1:2) = [-0.1*midv(1),0.1*midv(1)];
  40.     endif
  41.     if(midv(2) != 0)
  42.       axdel(3:4) = [-0.1*midv(2),0.1*midv(2)];
  43.     endif
  44.   else
  45.     # they're at least one-dimensional
  46.     if(delv(1) != 0)
  47.       axdel(1:2) = 1.1*[-delv(1),delv(1)];
  48.     endif
  49.     if(delv(2) != 0)
  50.       axdel(3:4) = 1.1*[-delv(2),delv(2)];
  51.     endif
  52.   endif
  53.   axvec = axmid + axdel; 
  54. endfunction
  55.  
  56.