home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 10.ddi / CONTROL.DI$ / PRINTMAT.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  2.8 KB  |  105 lines

  1. function [] = printmat(a,name,rlab,clab)
  2. %PRINTMAT Print matrix with labels.
  3. %
  4. %    PRINTMAT(A,NAME,RLAB,CLAB) prints the matrix A with the row labels
  5. %    RLAB and column labels CLAB.  NAME is a string used to name the 
  6. %    matrix.  RLAB and CLAB are string variables that contain the row
  7. %    and column labels delimited by spaces.  For example, the string
  8. %
  9. %        RLAB = 'alpha beta gamma';
  10. %
  11. %    defines 'alpha' as the label for the first row, 'beta' for the
  12. %    second row and 'gamma' for the third row.  RLAB and CLAB must
  13. %    contain the same number of space delimited labels as there are 
  14. %    rows and columns respectively.
  15. %
  16. %    PRINTMAT(A,NAME) prints the matrix A with numerical row and column
  17. %    labels.  PRINTMAT(A) prints the matrix A without a name.
  18. %
  19. %    See also: PRINTSYS.
  20.  
  21. %    Clay M. Thompson  9-24-90
  22. %    Copyright (c) 1986-93 by the MathWorks, Inc.
  23.  
  24. error(nargchk(1,4,nargin));
  25.  
  26. [nrows,ncols] = size(a);
  27.  
  28. if nargin<2, name = []; end
  29. if nargin==3, error('Wrong number of input arguments.'); end
  30. if nargin<4,
  31.   rlab = []; clab = [];
  32.   for i=1:nrows, rlab = [rlab, '--',int2str(i),'--> ']; end
  33.   for i=1:ncols, clab = [clab, '----',int2str(i),'---- ']; end
  34.   rlab=rlab(1:length(rlab)-1);
  35.   clab=clab(1:length(clab)-1);
  36. end
  37.  
  38. col_per_scrn=5;
  39. len=12;
  40.  
  41.  
  42. if (nrows==0)|(ncols==0), 
  43.   if ~isempty(name), disp(' '), disp([name,' = ']), end
  44.   disp(' ')
  45.   disp('     []')
  46.   disp(' ')
  47.   return
  48. end
  49.  
  50. % Remove extra spaces (delimiters)
  51. ndx1 = find(clab==' ');
  52. ndx2 = find([ndx1,0]==[-1,ndx1+1]);
  53. if ~isempty(clab), clab(ndx1(ndx2))=[]; end
  54.  
  55. ndx1 = find(rlab==' ');
  56. ndx2 = find([ndx1,0]==[-1,ndx1+1]);
  57. if ~isempty(rlab), rlab(ndx1(ndx2))=[]; end
  58.  
  59. % Determine position of delimiters
  60. cpos = find(clab==' ');
  61. if length(cpos)<ncols-1, error('Not enough column labels.'); end
  62. cpos = [0,cpos,length(clab)+1];
  63.  
  64. rpos = find(rlab==' ');
  65. if length(rpos)<nrows-1, error('Not enough row labels.'); end
  66. rpos = [0,rpos,length(rlab)+1];
  67.  
  68. col=1;
  69. n = min(col_per_scrn-1,ncols-1);
  70. disp(' ')
  71. if ~isempty(name), disp([name,' = ']), end    % Print name
  72. while col<=ncols
  73.   % Print labels
  74.   s = ' '*ones(1,len+1);
  75.   for j=0:n,
  76.     lab = clab(cpos(col+j)+1:cpos(col+j+1)-1);
  77.     if length(lab)>len,
  78.       lab=lab(1:len);
  79.     else
  80.       lab=[' '*ones(1,len-length(lab)),lab]; end
  81.     s= [s,' ',lab];
  82.   end
  83.   disp(s)
  84.   for i=1:nrows,
  85.     s = rlab(rpos(i)+1:rpos(i+1)-1); 
  86.     if length(s)>len, s=s(1:len); else s=[' '*ones(1,len-length(s)),s]; end
  87.     s = [' ',s];
  88.     for j=0:n,
  89.       element = a(i,col+j);
  90.       if element==0,
  91.         s=[s,'            0'];
  92.       elseif (element>=1.e6)|(element<=-1.e5)|(abs(element)<.0001)
  93.         s=[s,sprintf(' %12.5e',element)];
  94.       else
  95.         s=[s,sprintf(' %12.5f',element)];
  96.       end
  97.     end
  98.     disp(s)
  99.   end % for
  100.   col = col+col_per_scrn;
  101.   disp(' ')
  102.   if (ncols-col<n), n=ncols-col; end
  103. end % while
  104.  
  105.