fprintf

Write formatted data to a file

Syntax

y = fprintf ( file,format,... )
y = file.fprintf ( format,... )

Inputs

ArgumentTypeDescriptionUnit
filetext or scalarfile name string or file identifiern/a
formattextFormatted text to write to the file, following the same convention as in C language.-
......n/a-

Outputs / Return Value

Notes

Examples

To open the file (if file is not found, create one) and write an integer val at the end of the file log.txt; if the file is not found, create one:
  AUX> fprintf("log.txt","%%d\n", val)
Integers from 1 through 10 are summed consecutively. To create a file val to the file log.txt, and write each integer and the cumulative sum:
 AUX> sum=0; fd=fopen("log.txt","wt); for k=1:10, sum += k; fprintf(fd,"%%d %%d\n", k, sum); end, fclose(fd)
To make a formatted string output and show it on the console (this is useful inside a UDF):
 AUX> fprintf(0,"%%d\n", val)

See Also

Review Status