dlmwrite
Writes the values of a 2D matrix, m, to the file, f.
Syntax
dlmwrite(f, m)
dlmwrite(f, m, '-append', ...)
dlmwrite(f, m, d, r, c, ...)
dlmwrite(f, m, key-value, ...)
Inputs
- f
- File name or file handle.
- '-append' (optional)
- Keyword which appends the matrix data to the output file, f.
- m
- 2D Matrix. The default row delimiter is newline, '\n'. The default column delimiter is white space, ' '.
- d (optional)
- Specifies the delimiter between columns. The default delimiter is white space, ' '.
- r (optional)
- Specifies the number of lines containing only the column delimiter, d, at the beginning of the output file f.
- 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.
- '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'.
- 'delimiter', d
- Value for optional keyword 'delimiter'. See d for details.
- 'roffset', r
- Value for optional keyword 'roffset'. See r for details.
- 'coffset', c
- Value for optional keyword 'coffset'. See c for details.
- '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.
- '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.
Examples
f = fopen('Example1.txt', 'w');
dlmwrite(f, rand(2,2))
0.60276 0.85795
0.54488 0.84725
dlmwrite('Example2.txt', rand(2,2), ',', 1, 2)
,,
,,0.54881,0.59284
,,0.71519,0.84427
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
dlmwrite('Example4.txt', rand(2,2), 'delimiter', ', ', 'newline', 'pc', 'precision', '%0.3f')
0.383, 0.478
0.792, 0.812