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

  1. function S = sparse(X)
  2. %SPARSE    Build sparse matrix from nonzeros and indices.
  3. %    S = SPARSE(...) is the built-in function which generates matrices
  4. %    in MATLAB's sparse storage organization.  It can be called with 
  5. %    1, 2, 3, 5 or 6 arguments.
  6. %
  7. %    S = SPARSE(X) converts a sparse or full matrix to sparse form by
  8. %    squeezing out any zero elements.
  9. %
  10. %    S = SPARSE(i,j,s,m,n,nzmax) uses the rows of [i,j,s] to generate
  11. %    an m-by-n sparse matrix with space allocated for nzmax nonzeros.
  12. %    The two integer index vectors, i and j, and the real or complex
  13. %    entries vector, s, all have the same length, nnz, which is the
  14. %    number of nonzeros in the resulting sparse matrix S .
  15. %
  16. %    There are several simplifications of this six argument call.
  17. %
  18. %    S = SPARSE(i,j,s,m,n) uses nzmax = length(s).
  19. %
  20. %    S = SPARSE(i,j,s) uses m = max(i) and n = max(j).
  21. %
  22. %    S = SPARSE(m,n) abbreviates SPARSE([],[],[],m,n,0).  This
  23. %    generates the ultimate sparse matrix, an m-by-n all zero matrix.
  24. %
  25. %    The argument s and one of the arguments i or j may be scalars,
  26. %    in which case they are expanded so that the first three arguments
  27. %    all have the same length.
  28. %
  29. %    For example, this dissects and then reassembles a sparse matrix:
  30. %
  31. %               [i,j,s] = find(S);
  32. %               [m,n] = size(S);
  33. %               S = sparse(i,j,s,m,n);
  34. %
  35. %    So does this, if the last row and column have nonzero entries:
  36. %
  37. %               [i,j,s] = find(S);
  38. %               S = sparse(i,j,s);
  39. %
  40. %    All of MATLAB's built-in arithmetic, logical and indexing operations
  41. %    can be applied to sparse matrices, or to mixtures of sparse and
  42. %    full matrices.  Operations on sparse matrices return sparse matrices
  43. %    and operations on full matrices return full matrices.  In most cases,
  44. %    operations on mixtures of sparse and full matrices return full
  45. %    matrices.  The exceptions include situations where the result of
  46. %    a mixed operation is structurally sparse, eg.  A .* S is at least
  47. %    as sparse as S .  Some operations, such as S >= 0, generate
  48. %    "Big Sparse", or "BS", matrices -- matrices with sparse storage
  49. %    organization but few zero elements.
  50. %
  51. %    See also FULL, FIND and the sparfun directory.
  52.  
  53. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  54. %    Built-in function.
  55.