dlmwrite

Writes a numeric matrix to a delimited text file.

Category: Data Import and Analysis > Data Import and Export

Syntax

dlmwrite(filename, M)

Writes M with comma separators.

dlmwrite(filename, M, delimiter)

Uses the given delimiter.

dlmwrite(filename, M, Name, Value)

Sets 'delimiter', 'precision' or '-append'.

Description

Each matrix row becomes one line. The default precision is five significant digits, so pass 'precision' when you need more. writematrix is the recommended function for new code.

Input arguments

filename
Output file name.
M
Numeric matrix.
'delimiter'
Field separator, for example ';' or '\t'.
'precision'
Number of significant digits, or a format such as '%.4f'.
'-append'
Adds to the end of an existing file instead of overwriting it.

Example

Delimiter, precision and append

dlmwrite('o.txt', [1.23456789 2; 3 4], 'delimiter', ' ', 'precision', 4);
dlmwrite('o.txt', [10 20], '-append', 'delimiter', ' ');
disp(fileread('o.txt'))
Output
1.235 2
3 4
10 20

Notes

The 'roffset' and 'coffset' options are not applied in MatLivre.

See also

dlmread csvwrite writematrix fprintf