

The function recycles the format string through the elements of A (columnwise) until all the elements are used up.

The fprintf function behaves like its ANSI C language namesake with these exceptions and extensions. This table lists the escape character sequences you use to specify non-printing characters in a format specification. Hexadecimal notation (using uppercase letters A- F)Ĭonversion characters %o, %u, %x, and %X support subtype specifiers. Hexadecimal notation (using lowercase letters a- f) The more compact of %e or %f, as defined in. You can control the width and precision of the output by including these options in the format string.Ī digit string specifying the minimum number of digits to be printed.Ī digit string including a period (.) specifying the number of digits to be printed to the right of the decimal point.Ĭonversion characters specify the notation of the output.Įxponential notation (using a lowercase e as in 3.1415e+00)Įxponential notation (using an uppercase E as in 3.1415E+00) Left-justifies the converted argument in its field. You can control the alignment of the output using any of these optional flags. You specify these elements in the following order: The format string can contain escape characters to represent non-printing characters such as newline characters and tabs.Ĭonversion specifications begin with the % character and contain these optional and required elements:

A conversion specification controls the notation, alignment, significant digits, field width, and other aspects of output format. The format argument is a string containing C language conversion specifications. See fopen for more information.) Omitting fid causes output to appear on the screen. (It may also be 1 for standard output (the screen) or 2 for standard error. fprintf returns a count of the number of bytes written.Īrgument fid is an integer file identifier obtained from fopen. Gives 2 4 5 8 6 7 88 9 12.8 41.3 13.7 16 18 20 10.1 17.5 49.Fprintf (MATLAB Functions) MATLAB Function Referenceįormats the data in the real part of matrix A (and in any additional matrix arguments) under control of the specified format string, and writes it to the file associated with file identifier fid. If you can do with a trailing space, you do not need to build the format string with repetition, as fprintf can automatically recycle it for all the inputs: fprintf('%.8g ',a,b,c) Also, you can use the format specifier %g, which automatically prints integer values without decimals: fprintf(strjoin(),a,b,c) You can dynamically build the format string using repmat and strjoin. That is, should be printed as 4 4.1, not as 4 4.10000 or 4.00000 4.10000.Ĭ = % example with 9 decimal figures This answer assumes you don't need trailing decimal zeros.
