Writes the values of a 2D matrix, m, to the file, f.


dlmwrite(f, m)

dlmwrite(f, m, '-append', ...)

dlmwrite(f, m, d, r, c, ...)

dlmwrite(f, m, key-value, ...)


File name or file handle.
Type: string | int
'-append' (optional)
Keyword which appends the matrix data to the output file, f.
Type: string
2D Matrix. The default row delimiter is newline, '\n'. The default column delimiter is white space, ' '.
Type: matrix
d (optional)
Specifies the delimiter between columns. The default delimiter is white space, ' '.
Type: string
r (optional)
Specifies the number of lines containing only the column delimiter, d, at the beginning of the output file f.
Type: integer
c (optional)
Specifies the number of lines of data in the output file f, which have the column delimiters, d, added to the start of the line.
Type: integer
'append', appendval
Value for optional keyword 'append' specifying whether the data is appended to the output file f. Valid values for appendval are 'on' and 'off'.
Type: string
'delimiter', d
Value for optional keyword 'delimiter'. See d for details.
Type: string
'roffset', r
Value for optional keyword 'roffset'. See r for details.
Type: integer
'coffset', c
Value for optional keyword 'coffset'. See c for details.
Type: integer
'precision', p
Value for the optional keyword 'precision', specifying a string that will be used by 'fprintf' for writing formatted matrix data or the number of significant digits. The default will be the format specified in the application at the time of execution.
Type: string | int
'newline', n
Value for the optional keyword 'newline', specifying the delimiter between rows. Reserved values of 'pc', 'unix or 'mac' use '\r\n', '\n' and '\r' as row delimiters respectively. Users can also specify any other delimiter using n.
Type: string


Default options with file descriptor:
f = fopen('Example1.txt', 'w');
dlmwrite(f, rand(2,2))
0.60276 0.85795
0.54488 0.84725
Delimiter, row offset, and column offset options:
dlmwrite('Example2.txt', rand(2,2), ',', 1, 2)
Append, roffset, and coffset keywords:
dlmwrite('Example1.txt', rand(3,2), 'append', 'on', 'roffset', 1, 'coffset', 1)
0.60276 0.85795
0.54488 0.84725
0.42365 0.62356
0.64589 0.38438
0.43759 0.29753
Delimiter, newline, and precision keywords:
dlmwrite('Example4.txt', rand(2,2), 'delimiter', ', ', 'newline', 'pc', 'precision', '%0.3f')
0.383, 0.478
0.792, 0.812