home *** CD-ROM | disk | FTP | other *** search
/ APDL Eductation Resources / APDL Eductation Resources.iso / programs / electronic / rlab / TestMatrix / cpltaxes_r < prev    next >
Encoding:
Text File  |  1994-12-20  |  1.7 KB  |  71 lines

  1. //-------------------------------------------------------------------//
  2.  
  3. // Synopsis:   Determine suitable AXIS for plot of complex vector.
  4.  
  5. // Syntax:     X = cpltaxes ( Z )
  6.  
  7. // Description:
  8.  
  9. //      cpltaxes determines a 4-vector X such that
  10. //      plimits(X[1],x[2],x[3].x[4]) sets axes for a plot of Z that
  11. //      has axes of equal length and leaves a reasonable amount of
  12. //      space around the edge of the plot.
  13.  
  14. //      Called by fv(), gersh(), ps() and pscont().
  15.  
  16. //    This file is a translation of cpltaxes.m from version 2.0 of
  17. //    "The Test Matrix Toolbox for Matlab", described in Numerical
  18. //    Analysis Report No. 237, December 1993, by N. J. Higham.
  19.  
  20. //-------------------------------------------------------------------//
  21.  
  22. cpltaxes = function ( z )
  23. {
  24.   // Set x and y axis ranges so both have the same length.
  25.   
  26.   xmin = min(real(z)); xmax = max(real(z));
  27.   ymin = min(imag(z)); ymax = max(imag(z));
  28.   
  29.   // Fix for rare case of `trivial data'.
  30.   if (xmin == xmax)
  31.   {
  32.     xmin = xmin - 1/2; 
  33.     xmax = xmax + 1/2;
  34.   }
  35.   if (ymin == ymax)
  36.   {
  37.     ymin = ymin - 1/2; 
  38.     ymax = ymax + 1/2;
  39.   }
  40.  
  41.   if (xmax-xmin >= ymax-ymin)
  42.   {
  43.     ymid = (ymin + ymax)/2;
  44.     ymin =  ymid - (xmax-xmin)/2; 
  45.     ymax = ymid + (xmax-xmin)/2;
  46.   else
  47.     xmid = (xmin + xmax)/2;
  48.     xmin = xmid - (ymax-ymin)/2; 
  49.     xmax = xmid + (ymax-ymin)/2;
  50.   }
  51.   
  52.   // Scale ranges by 1+2*alpha to give extra space around edges of plot.
  53.  
  54.   alpha = 0.1;
  55.   x[1] = xmin - alpha*(xmax-xmin);
  56.   x[2] = xmax + alpha*(xmax-xmin);
  57.   x[3] = ymin - alpha*(ymax-ymin);
  58.   x[4] = ymax + alpha*(ymax-ymin);
  59.  
  60.   if (x[1] == x[2])
  61.   {
  62.     x[2] = x[2] + 0.1;
  63.   }
  64.   if (x[3] == x[4])
  65.   {
  66.     x[4] = x(3) + 0.1;
  67.   }
  68.  
  69.   return x;
  70. };
  71.