home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / GRAPHICS.DI$ / AXIS.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  6.5 KB  |  214 lines

  1. function [ans1, ans2, ans3] = axis(arg1, arg2, arg3, arg4);
  2. %AXIS    Plot axis scaling and appearance.
  3. %     AXIS([XMIN XMAX YMIN YMAX]) sets scaling for the x- and y-axes
  4. %     on the current plot.
  5. %     AXIS([XMIN XMAX YMIN YMAX ZMIN ZMAX]) sets the scaling for the
  6. %     x-, y- and z-axes on the current 3-D plot.
  7. %     AXIS('auto') returns the axis scaling to its default, automatic
  8. %     mode where, for each plot, xmin = min(x), xmax = max(x), etc.
  9. %     V = AXIS returns a row vector containing the scaling for the
  10. %     current plot.  If the current plot is two-dimensional, V has
  11. %     four components; if it is three-dimensional, V has six components.
  12. %     AXIS(AXIS) freezes the scaling at the current limits, so that if
  13. %    HOLD is turned on, subsquent plots will use the same limits.
  14. %     AXIS('ij') puts MATLAB into its "matrix" axes mode.  The coordinate
  15. %     system origin is at the upper left corner.  The i axis is vertical
  16. %     and is numbered from top to bottom.  The j axis is horizontal and
  17. %     is numbered from left to right.
  18. %     AXIS('xy') puts MATLAB into its default "Cartesian" axes mode.
  19. %     The coordinate system origin is at the lower left corner.  The x axis
  20. %     is horizontal and is numbered from left to right.  The y axis is
  21. %     vertical and is numbered from bottom to top.
  22. %     AXIS('equal') changes the current axis box size so that equal tick
  23. %    mark increments on the x- and y-axis are equal in size. This makes
  24. %    PLOT(SIN(X),COS(X)) look like a circle, instead of an oval.
  25. %     AXIS('square') makes the current axis box square in size.
  26. %     AXIS('image'), for images, makes the aspect ratio the same size as
  27. %     the image.  
  28. %
  29. %     AXIS('normal') restores the current axis box to full size and
  30. %    removes any restrictions on the scaling of the units.
  31. %    This undoes the effects of AXIS('square') and AXIS('equal').
  32. %
  33. %    AXIS('image') sets the aspect ratio and the axis limits so the
  34. %    image in the current axes has square pixels.
  35. %     AXIS('off') turns off all axis labeling and tick marks.
  36. %     AXIS('on') turns axis labeling and tick marks back on.
  37. %     [S1,S2,S3] = AXIS('state') returns strings indicating the
  38. %     current setting of three axis properties.  
  39. %        S1 = 'auto' or 'manual'.
  40. %        S2 = 'on' or 'off'.
  41. %        S3 = 'xy' or 'ij'.
  42.  
  43.  
  44. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  45.  
  46. ax = gca;
  47.  
  48. if(nargin == 0)
  49.     ans1 = [get(ax,'XLim') get(ax,'YLim')];
  50.     v = get(ax,'View');
  51.     if(v ~= [0 90])
  52.         ans1 = [ans1 get(ax,'ZLim')];
  53.     end
  54. elseif(nargin == 1 & ~isstr(arg1))
  55.     if((max(size(arg1)) == 4) | (max(size(arg1)) == 6))
  56.         set(ax,'XLim',arg1(1:2),'YLim',arg1(3:4),...
  57.             'XLimMode','manual','YLimMode','manual');
  58.         if(max(size(arg1)) == 6)
  59.             set(ax,'ZLim',arg1(5:6),'ZLimMode','manual');
  60.         end
  61.         if max(size(arg1)) == 4 & ~ishold
  62.             view(2);
  63.         elseif max(size(arg1)) == 6
  64.             if (get(ax,'View') == [0 90] & ~ishold)
  65.                 view(3);
  66.             end
  67.         end
  68.     else
  69.         error('Vector must have 4 or 6 elements.')
  70.     end
  71. else
  72.     for i = 1:nargin
  73.         cur_arg = eval(['arg',num2str(i)]);
  74.  
  75.         %
  76.         % handle AUTO, AUTO[XYZ]:
  77.         %
  78.         if(strcmp(cur_arg(1:min(4,max(size(cur_arg)))),'auto'))
  79.  
  80.             do_all = (max(size(cur_arg)) == max(size('auto')));
  81.             do_x = max(size(find(cur_arg == 'x')));
  82.             do_y = max(size(find(cur_arg == 'y')));
  83.             do_z = max(size(find(cur_arg == 'z')));
  84.             if(do_all | do_x)
  85.                 set(ax,'XLimMode','auto');
  86.             else
  87.                 set(ax,'XLimMode','manual');
  88.             end
  89.             if(do_all | do_y)
  90.                 set(ax,'YLimMode','auto');
  91.             else
  92.                 set(ax,'YLimMode','manual');
  93.             end
  94.             if(do_all | do_z)
  95.                 set(ax,'ZLimMode','auto');
  96.             else
  97.                 set(ax,'ZLimMode','manual');
  98.             end
  99.  
  100.         %
  101.         % handle MANUAL:
  102.         %
  103.         elseif(strcmp(cur_arg, 'manual'))
  104.             set(ax,'XLimMode','manual','YLimMode','manual','ZLimMode','manual');
  105.  
  106.         %
  107.         % handle IJ:
  108.         %
  109.         elseif(strcmp(cur_arg, 'ij'))
  110.             set(ax,'XDir','normal');
  111.             set(ax,'YDir','reverse');
  112.  
  113.         %
  114.         % handle XY:
  115.         %
  116.         elseif(strcmp(cur_arg, 'xy'))
  117.             set(ax,'XDir','normal');
  118.             set(ax,'YDir','normal');
  119.  
  120.         %
  121.         % handle SQUARE:
  122.         %
  123.         elseif(strcmp(cur_arg, 'square')) 
  124.             a = get(ax,'Aspect');
  125.             set(ax,'Aspect',[1,a(2)])
  126.  
  127.         %
  128.         % handle EQUAL:
  129.         %
  130.         elseif(strcmp(cur_arg, 'equal')) 
  131.             a = get(ax,'Aspect');
  132.             set(ax,'Aspect',[a(1),1])
  133.  
  134.         %
  135.         % handle NORMAL:
  136.         %
  137.         elseif(strcmp(cur_arg, 'normal'))
  138.             set(ax,'Aspect',[nan nan])
  139.  
  140.         %
  141.         % handle IMAGE:
  142.         %
  143.         elseif(strcmp(cur_arg,'image'))
  144.             m = diff(get(ax,'Ylim'));
  145.             n = diff(get(ax,'Xlim'));
  146.             set(ax,'Aspect',[n/m 1])
  147.  
  148.         %
  149.         % handle OFF:
  150.         %
  151.         elseif(strcmp(cur_arg, 'off'))
  152.             set(ax,'Visible','off');
  153.  
  154.         %
  155.         % handle ON:
  156.         %
  157.         elseif(strcmp(cur_arg, 'on'))
  158.             set(ax,'Visible','on');
  159.  
  160.         %
  161.         % handle STATE:
  162.         %
  163.         elseif(strcmp(cur_arg, 'state'))
  164.             str = '';
  165.             if(strcmp(get(ax,'XLimMode'), 'auto'))
  166.                 str = 'x';
  167.             end
  168.             if(strcmp(get(ax,'YLimMode'), 'auto'))
  169.                 str = [str, 'y'];
  170.             end
  171.             if(strcmp(get(ax,'ZLimMode'), 'auto'))
  172.                 str = [str, 'z'];
  173.             end
  174.             if(max(size(str)) == 3)
  175.                 ans1 = 'auto';
  176.             else
  177.                 ans1 = 'manual';
  178.             end
  179.  
  180.             if(nargout > 1)
  181.                 if strcmp(get(ax,'Visible'),'on')
  182.                     ans2 = 'on';
  183.                 else
  184.                     ans2 = 'off';
  185.                 end
  186.             end
  187.  
  188.             if(nargout > 2)
  189.                 ans3 = 'xy';
  190.                 if(    strcmp(get(ax,'XDir'),'normal') & ...
  191.                     strcmp(get(ax,'YDir'),'reverse'))
  192.                         ans3 = 'ij';
  193.                 end
  194.             end
  195.  
  196.         %
  197.         % handle ERROR (NONE OF THE ABOVE STRINGS FOUND):
  198.         %
  199.         else
  200.             error(['Unknown command option ''',cur_arg,'''']);
  201.         end
  202.     end
  203. end
  204.