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

  1. function [hc,hb] = compass(x,y,s)
  2. %COMPASS Compass plot.
  3. %    COMPASS(Z) draws a graph that displays the angle and magnitude
  4. %    of the complex elements of Z as arrows emanating from the origin.
  5. %
  6. %    COMPASS(X,Y) is equivalent to COMPASS(X+i*Y).  It displays the
  7. %    compass plot for the angles and magnitudes of the elements of
  8. %    matrices X and Y.
  9. %
  10. %    COMPASS(Z,'S') and COMPASS(X,Y,'S') use line style 'S' where
  11. %    'S' is any legal linetype as described under the PLOT command.
  12. %
  13. %    See also ROSE, FEATHER, QUIVER.
  14.  
  15. %    Charles R. Denham, MathWorks 3-20-89
  16. %    Modified, 1-2-92, LS.
  17. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  18.  
  19. a = ((0:4) + 1./2) ./ 4;
  20. sq = sqrt(2) .* exp(-sqrt(-1) .* 2 .* pi .* a);
  21.  
  22. xx = [0 1 .8 1 .8].';
  23. yy = [0 0 .08 0 -.08].';
  24. arrow = xx + yy.*sqrt(-1);
  25.  
  26. if nargin == 2
  27.    if isstr(y)
  28.       s = y;
  29.       y = imag(x); x = real(x);
  30.      else
  31.       s = 'r-';
  32.    end
  33.   elseif nargin == 1
  34.    s = 'r-';
  35.    y = imag(x); x = real(x);
  36. end
  37.  
  38. x = x(:);
  39. y = y(:);
  40. if length(x) ~= length(y)
  41.    error('X and Y must be same length.');
  42. end
  43.  
  44. z = (x + y.*sqrt(-1)).';
  45. a = arrow * z;
  46. mx = max(max(abs(a)));
  47. next = lower(get(gca,'NextPlot'));
  48. isholdon = ishold;
  49. b = plot(real(sq), imag(sq), 'w:'); hold on
  50. h = plot(real(a), imag(a), s);
  51. axis('equal')
  52. if ~isholdon
  53.    set(gca,'NextPlot',next);
  54. end
  55. if nargout > 0
  56.    hc = h;
  57.    hb = b;
  58. end
  59.