Skip to content

dlmwrite

io · scripts/io/dlmwrite.m

: dlmwrite (file, M)
: dlmwrite (file, M, delim, r, c)
: dlmwrite (file, M, key, val …)
: dlmwrite (file, M, "-append", …)

Write the matrix M as delimited text.

file is a file name. Values within a row are separated by delim, a comma unless another delimiter is given, and numbers are written with five significant digits unless the "precision" option says otherwise. r extra lines containing only delimiters are written before the data and c extra delimiters are written at the start of every data line. "-append" adds to the end of an existing file instead of replacing it.

The same settings, and a few more, can be given as keyword/value pairs after M:

"append"

"on" or "off"; the same as "-append".

"delimiter"

the separator between values on a line.

"newline"

the text written between rows. "unix", "pc" and "mac" stand for "\n", "\r\n" and "\r"; anything else is written literally.

"roffset"

the number of leading delimiter-only lines, like r.

"coffset"

the number of leading delimiters on each data line, like c.

"precision"

how numbers are printed: either a printf conversion such as "%10.4f" or a count of significant digits.

dlmwrite ("table.csv", magic (4));
dlmwrite ("table.tex", magic (4), "delimiter", "&", "newline", "\n");