home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 9.ddi / IDENT.DI$ / SUM4VMS.M < prev    next >
Encoding:
Text File  |  1993-02-05  |  556 b   |  25 lines

  1. function y=sum4vms(x)
  2. %SUM    Sum of the elements.
  3. %       For vectors, SUM(X) is the sum of the elements of X.
  4. %       For matrices, SUM(X) is a row vector with the sum over
  5. %       each column. SUM(DIAG(X)) is the trace of X.
  6. %       See also PROD, CUMPROD, CUMSUM.
  7. %
  8. if isempty(find(isnan(x)))
  9.   %regular sum
  10.   y=sum(x)
  11. else
  12.   [t1,t2]=size(x);
  13.   if min(t1,t2) == 1
  14.     y=NaN;
  15.   else
  16.     for i=1:t2
  17.       if isempty(find(isnan(x(:,i))))
  18.         y(i) = sum(x(:,i));
  19.       else
  20.         y(i) = NaN;
  21.       end;
  22.     end;
  23.   end;
  24. end;