home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / ELMAT.DI$ / ROT90.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  853 b   |  41 lines

  1. function B = rot90(A,k)
  2. %ROT90    Rotate matrix 90 degrees.
  3. %    rot90(A) is the 90 degree rotation of m x n matrix A.
  4. %    rot90(A,k) is the k*90 degree rotation of A, k = +-1,+-2,...
  5. %    For example,
  6. %
  7. %          A = [1 2 3      B = rot90(A) = [ 3 6
  8. %               4 5 6 ]                     2 5
  9. %                                           1 4 ]
  10. %
  11. %    mesh(B) then shows a 90 degree counter-clockwise rotation
  12. %    of mesh(A).
  13. %
  14. %    See also VIEW, FLIPUD, FLIPLR.
  15.  
  16. %    From John de Pillis 19 June 1985
  17. %    Modified 12-19-91, LS.
  18. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  19.  
  20.  
  21. [m,n] = size(A);
  22. if nargin == 1
  23.     k = 1;
  24. else
  25.     k = rem(k,4);
  26.     if k < 0
  27.         k = k + 4;
  28.     end
  29. end
  30. if k == 1
  31.     A = A.';
  32.     B = A(n:-1:1,:);
  33. elseif k == 2
  34.     B = A(m:-1:1,n:-1:1);
  35. elseif k == 3
  36.     B = A(m:-1:1,:);
  37.     B = B.';
  38. else
  39.     B = A;
  40. end
  41.