fprintf
Write formatted data to a file or the console.
Syntax
Section titled “Syntax”fprintf(format, A, ...)fprintf(fid, format, A, ...)[count, errmsg] = fprintf(...)Description
Section titled “Description”Formats arguments with C-style format specifiers (%d, %f, %s, etc.) and writes the result. Without fid, writes to the console. With a fid from fopen, writes to that file. Two-output form returns the byte count and any error message.
Examples
Section titled “Examples”fprintf('Result: %d\n', 42)fid = fopen('log.txt', 'a'); fprintf(fid, '%s\n', msg); fclose(fid);