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

  1. function S = spconvert(D)
  2. %SPCONVERT Convert from sparse external format.
  3. %    S = SPCONVERT(D) converts an nnz or nnz+1 by 3 or 4 array
  4. %    with rows containing [i,j,s] or [i,j,real(s(i,j)),imag(s(i,j))]
  5. %    to the corresponding sparse matrix.  A row of the form [m n 0]
  6. %    or [m n 0 0] anywhere in D may be used to specify size(S).
  7. %    If D is already sparse no conversion is done, so SPCONVERT can
  8. %    be used after D is loaded from either a MAT or an ASCII file.
  9. %
  10. %    See also SPARSE, FULL.
  11.  
  12. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  13.  
  14. if ~issparse(D)
  15.     [nnz,na] = size(D);
  16.     if na == 3
  17.        S = sparse(D(:,1),D(:,2),D(:,3));
  18.     elseif na == 4
  19.        S = sparse(D(:,1),D(:,2),D(:,3)+i*D(:,4));
  20.     else
  21.        error('Array D must have 3 or 4 columns.')
  22.     end
  23. end
  24.