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

  1. %SPRINTF Write formatted data to a string.
  2. %    [S,ERRMSG] = SPRINTF(FORMAT,A,...) formats the data in matrix A
  3. %    (and in any additional matrix arguments), under control of the
  4. %    specified FORMAT string, and returns it in the MATLAB string variable
  5. %    S. ERRMSG is an optional output argument that returns an error
  6. %    message string if an error occurred or an empty matrix if an error
  7. %    did not occur.
  8. %
  9. %    SPRINTF is the same as FPRINTF except that it returns the data in
  10. %    a MATLAB string variable rather than writing it to a file.
  11. %
  12. %       FORMAT is a string containing C language conversion specifications.
  13. %       Conversion specifications involve the character %, optional flags,
  14. %       optional width and precision fields, optional subtype specifier, and
  15. %       conversion characters d, i, o, u, x, X, f, e, E, g, G, c, and s.
  16. %       See a C manual for complete details.
  17. %
  18. %       SPRINTF behaves like ANSI C with certain exceptions and extensions.
  19. %       These include:
  20. %
  21. %       1. If the MATLAB double doesn't convert exactly to the datatype
  22. %          associated with the conversion specifier then e format is used.
  23. %          You must explicitly convert non-integral MATLAB values to
  24. %          integral values if you plan to use an integral conversion
  25. %          specifier like d and get the expected ANSI C behavior.
  26. %       2. The following non-standard subtype specifiers are supported for
  27. %          conversion characters o, u, x, and X.
  28. %
  29. %          t    - The underlying C datatype is a float rather than an
  30. %                 unsigned integer.
  31. %          b    - The underlying C datatype is a double rather than an
  32. %                 unsigned integer.
  33. %
  34. %          For example, to print out in hex a double value use a format like
  35. %          '%bx'.
  36. %
  37. %    SPRINTF differs from its C language namesake in an important
  38. %    respect - it is "vectorized" for the case when A is nonscalar. The
  39. %    format string is recycled through the elements of A (columnwise) until
  40. %    all the elements are used up. It is then recycled in a similar manner, 
  41. %    without reinitializing, through any additional matrix arguments.
  42. %
  43. %    For example, the statement
  44. %
  45. %        S = sprintf('rho is %5.3f',(1+sqrt(5))/2)
  46. %
  47. %    produces the string
  48. %
  49. %        S = 'rho is 1.618'
  50. %
  51. %    See also FPRINTF, SSCANF, FWRITE, NUM2STR, INT2STR.
  52.  
  53. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  54. %    Built-in function.
  55.