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

  1. function spy(S,arg2,arg3);
  2. %SPY       Visualize the sparsity structure.
  3. %     SPY(S) plots the sparsity pattern of any matrix S.
  4. %    SPY(S,color) uses the specified marker color instead of yellow.
  5. %    SPY(S,marksize) uses the specified marker size instead of
  6. %    a size which depends upon the figure size and the matrix order.
  7. %    SPY(S,color,marksize) and SPY(S,marksize,color) are allowed.
  8.  
  9. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  10.  
  11. color = 'y';
  12. marksize = 0;
  13. if nargin >= 2
  14.    if isstr(arg2), color = arg2; else, marksize = arg2; end
  15. end
  16. if nargin >= 3
  17.    if isstr(arg3), color = arg3; else, marksize = arg3; end
  18. end
  19.  
  20. [m,n] = size(S);
  21. [i,j] = find(S);
  22. nz = length(i);
  23. if nz > 0
  24.     h = plot(j,i,[color '.']);
  25.     if marksize == 0
  26.        units = get(gca,'units');
  27.        set(gca,'units','points');
  28.        pos = get(gca,'position');
  29.        marksize = max(1,min(15,round(3*min(pos(3:4))/max(m,n))));
  30.        set(gca,'units',units);
  31.     end
  32.     set(h,'markersize',marksize);
  33. else
  34.     if ~ishold, plot([],[],'.'), end
  35.     if m > 0
  36.         text((n+1)/2,(m+1)/2,'0');
  37.     else
  38.         m = eps; n = eps;
  39.         text((n+1)/2,(m+1)/2,'Empty');
  40.     end
  41. end
  42. xlabel(['nz = ' int2str(nz)]);
  43. if ~ishold
  44.     axis('ij')
  45.     axis([0 n+1 0 m+1]);
  46.     set(gca,'aspect',[n/m,1])
  47. end
  48.