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

  1. function [tout,rout] = rose(theta,x)
  2. %ROSE    Plot rose or angle histogram.
  3. %
  4. %    ROSE(THETA) plots the angle histogram for the angles in THETA.  
  5. %    The angles in the vector THETA must be specified in radians.
  6. %
  7. %    ROSE(THETA,N) where N is a scalar, uses N equally spaced bins 
  8. %    from 0 to 2*PI.  The default value for N is 20.
  9. %
  10. %    ROSE(THETA,X) where X is a vector, draws the histogram using the
  11. %    bins specified in X.
  12. %
  13. %    [T,R] = ROSE(...) returns the vectors T and R such that 
  14. %    POLAR(T,R) is the histogram.  No plot is drawn.
  15.  
  16. %    Clay M. Thompson 7-9-91
  17. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  18.  
  19. if isstr(theta)
  20.         error('Input arguments must be numeric.');
  21. end
  22. theta = rem(theta,2*pi);
  23. if nargin==1,
  24.   x = [0:19]*pi/10+pi/20;
  25.  
  26. elseif nargin==2,
  27.   if isstr(x)
  28.         error('Input arguments must be numeric.');
  29.   end
  30.   if max(size(x))==1,
  31.     x = [0:x-1]*2*pi/x + pi/x;
  32.   else
  33.     x = sort(rem(x(:)',2*pi));
  34.   end
  35.  
  36. end
  37. if isstr(x) | isstr(theta)
  38.         error('Input arguments must be numeric.');
  39. end
  40. [nn,xx] = hist(theta,x);    % Get histogram
  41.  
  42. % Form radius values for histogram triangle
  43. if min(size(nn))==1, % Vector
  44.   nn = nn(:); 
  45.  xx=xx(:);
  46. end
  47. [m,n] = size(nn);
  48. mm = 4*m;
  49. r = zeros(mm,n);
  50. r(2:4:mm,:) = nn;
  51. r(3:4:mm,:) = nn;
  52.  
  53. % Form theta values for histogram triangle from triangle centers (xx)
  54. yy = [2*xx(1)-xx(2);xx;2*xx(m)-xx(m-1)];
  55. zz = ([0;yy] + [yy;0])/2;
  56. zz = zz(2:m+2,:);
  57.  
  58. t = zeros(mm,1);
  59. t(2:4:mm) = zz(1:m);
  60. t(3:4:mm) = zz(2:m+1);
  61.  
  62. if nargout==0
  63.   polar(t,r)
  64.   return
  65. end
  66.  
  67. if min(size(nn))==1,
  68.   tout = t'; rout = r';
  69. else
  70.   tout = t; rout = r;
  71. end
  72.  
  73.  
  74.