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

  1. function t = num2str(x)
  2. %NUM2STR Number to string conversion.
  3. %    T = NUM2STR(X)  converts the scalar number  X into a string
  4. %    representation  T  with about  4  digits and an exponent if
  5. %    required.   This is useful for labeling plots with the
  6. %    TITLE, XLABEL, YLABEL, and TEXT commands.
  7. %
  8. %    See also INT2STR, SPRINTF, FPRINTF.
  9.  
  10. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  11.  
  12. if isstr(x)
  13.     t = x;
  14. else
  15.     t = sprintf('%.4g',real(x));
  16.     if imag(x) > 0
  17.        t = [t '+' sprintf('%.4g',imag(x)) 'i'];
  18.     elseif imag(x) < 0
  19.        t = [t '-' sprintf('%.4g',imag(x)) 'i'];
  20.     end
  21. end
  22.