MATLAB Function Reference Previous page   Next Page
dlmwrite

Write matrix to ASCII-delimited file

Syntax

Description

dlmwrite('filename', M) writes matrix M into an ASCII format file using the default delimiter (,) to separate matrix elements. The data is written starting at the first column of the first row in the destination file, filename.

dlmwrite('filename', M, 'D') writes matrix M into an ASCII format file, using delimiter D to separate matrix elements. The data is written starting at the first column of the first row in the destination file, filename. A comma (,) is the default delimiter. Use \t to produce tab-delimited files.

dlmwrite('filename', M, 'D', R, C) writes matrix A into an ASCII format file, using delimiter D to separate matrix elements. The data is written starting at row R and column C in the destination file, filename. R and C are zero based, so that R=0, C=0 specifies the first value in the file, which is the upper left corner.

dlmwrite('filename', M, 'attrib1', value1, 'attrib2', value2, ...) is an alternate syntax to those shown above, in which you specify any number of attribute-value pairs in any order in the argument list. Each attribute must be immediately followed by a corresponding value (see the table below).

Attribute
Value
delimiter
Delimiter string to be used in separating matrix elements
newline
Character(s) to use in terminating each line (see table below)
roffset
Offset, in rows, from the top of the destination file to where matrix data is to be written. Offset is zero based.
coffset
Offset, in columns, from the left side of the destination file to where matrix data is to be written. Offset is zero based.
precision
Numeric precision to use in writing data to the file. Specify the number of significant digits or a C-style format string starting in %, such as '%10.5f'.

This table shows which values you can use when setting the newline attribute.

Line Terminator
Description
'pc'
PC terminator (implies carriage return/line feed (CR/LF))
'unix'
UNIX terminator (implies line feed (LF))

dlmwrite('filename', M, '-append') appends the matrix to the file. If you do not specify '-append', dlmwrite overwrites any existing data in the file.

dlmwrite('filename', M, '-append', attribute-value list) is the same as the syntax shown above, but accepts a list of attribute-value pairs. You can place the '-append' flag in the argument list anywhere between attribute-value pairs, but not in between an attribute and its value.

Remarks

The resulting file is readable by spreadsheet programs.

Examples

Export matrix M to a file delimited by the tab character and using a precision of six significant digits:

Export matrix M to a file using a precision of six decimal places and the conventional line terminator for the PC platform:

Export matrix M to a file, and then append an additional matrix to the file that is offset one row below the first:

See Also

dlmread, csvwrite, csvread, wk1write, wk1read


Previous page  dlmread dmperm Next page

© 1994-2005 The MathWorks, Inc.