Documentation

dlmwrite

写矩阵to ASCII-delimited file

Syntax

dlmwrite(文件名,m)
dlmwrite(文件名,m,' - append')
dlmwrite(___,名称,值)
dlmwrite(文件名,M,定界符)
dlmwrite(filename,M,delimiter,row,col)

描述

example

dlmwrite(filename,M)writes numeric data in arrayMto an ASCII format file,filename, using the default delimiter (,)分开数组元素。如果文件,filename, already exists,dlmwriteoverwrites the file.

example

dlmwrite(filename,M,'-附加')appends the data to the end of the existing file,filename.

example

dlmwrite(___,Name,Value)另外,使用一个或多个名称值对参数指定定界符,newline字符,偏移和精度选项。

dlmwrite(filename,M,delimiter)writes arrayMto the file,filename, using the specified delimiter,delimiter, to separate array elements.

dlmwrite(filename,M,delimiter,,上校)writes the array starting at the specified row and column上校, in the destination file. Empty elements separated bydelimiter填充领先的行和列。

例子

全部收缩

创建一系列示例数据,M.

M = magic(3);

写矩阵M到文件,'myFile.txt', using the default delimiter (,).

dlmwrite('myFile.txt',M)

View the data in the file.

type('myFile.txt')
8,1,6 3,5,7 4,9,2

创建一系列示例数据,M.

M = magic(3)*pi
M =25.1327 3.1416 18.8496 9.4248 15.7080 21.9911 12.5664 28.2743 6.2832

写矩阵M到文件,'myFile.txt',由标签字符界定,并使用3个显着数字的精度。

dlmwrite('myFile.txt',M,“定界符”,'\t','precision',3)

View the data in the file.

type('myFile.txt')
25.1 3.14 18.8 9.42 15.7 22 12.6 28.3 6.28

Create two arrays of sample numeric data.

M =魔术(5);n =魔术(3);

Export matrixMto a file and use whitespace as the delimiter.

dlmwrite('myFile.txt',M,“定界符”,' ');

Append matrixNto the file, offset from the existing data by one row. Then, view the file.

dlmwrite('myFile.txt',N,'-append',...“定界符”,' ',“roffset”,1)类型('myFile.txt')
17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 8 1 6 3 5 7 4 9 2

Read the data in'myFile.txt'usingdlmread.

dlmread ('myFile.txt')
ans =17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 8 1 6 0 0 3 5 7 0 0 4 9 2 0 0

什么时候dlmreadreads the two matrices from the file, it pads the smaller matrix with zeros.

创建样本数字数据的数组。

M = magic(3);

Export matrixM使用6个小数位置的精度到文件。

dlmwrite('myFile.txt',M,'precision','%.6f');

View the data in the file.

type('myFile.txt')
8.000000,1.000000,6.000000 3.000000,5.000000,7.000000 4.000000,9.000000,2.000000

Input Arguments

全部收缩

要编写的文件名,指定为字符向量或字符串。

例子:'myFile.txt'或者"myFile.txt"

Data Types:char|string

编写的数字数据,指定为矩阵或数字值的单元格数组,每个单元格一个值。

例子:[1,2,3;4,5,6]

例子:{1,2,3;4,5,6}

Data Types:single|double|int8|INT16|INT32|int64|uint8|UINT16|uint32|uint64|logical|细胞
Complex Number Support:Yes

Delimiter to separate array elements, specified as a character vector or string, containing a single character or characters of a control sequence. Use'\t'to produce tab-delimited files.

例子:';'或者";"

例子:'\t'或者"\t"

Data Types:char|string

行偏移,指定为标量。行偏移指示在编写数字数据之前要跳过的行数。is zero-based, so that行= 0指示MATLAB®开始在目标文件的第一行中写作。跳过的行填充了指定的定界符。

Column offset, specified as a scalar. The column offset indicates the number of columns to skip before writing the numeric data.上校is zero-based, so that上校= 0指示MATLAB开始在目标文件的第一列中写作。跳过的列与指定的定界符分开。

名称值对参数

Specify optional comma-separated pairs ofName,Value参数。Nameis the argument name and价值是相应的值。Name必须出现在单引号中(' '). You can specify several name and value pair arguments in any order asNAME1,Value1,...,Namen,Valuen.

例子:dlmwrite('myFile.txt',M,'precision',4,'delimiter',' ')writes the numeric values in arrayMwith four significant digits and delimited using the whitespace character.

全部收缩

分隔符至分开的数组元素,指定为逗号分隔对“定界符”和字符向量或字符串,包含一个控制序列的单个字符或字符。利用'\t'to produce tab-delimited files.

例子:“定界符”,';'或者“定界符”,";"

例子:“定界符”,'\t'或者“定界符”,"\t"

Data Types:char|string

行偏移,指定为逗号分隔对“roffset”和标量。行偏移指示在编写数字数据之前要跳过的行数。These rows are populated with the specified delimiter. When appending to an existing file, the new data is offset from the end of the existing data.

The row offset is zero-based, so that“roffset”,0指示MATLABto begin writing in the first row of the destination file, which is the default. However, when appending to a file,“roffset”,0指示MATLAB在现有数据后立即开始在第一行中写作。

例子:“roffset”,2

从目标文件左侧的列偏移量,指定为逗号分隔对'咖啡店'和标量。列偏移指示在编写数字数据之前要跳过的列数。这些列与指定的定界符分开。

The column offset is zero-based, so that'咖啡店',0指示MATLAB开始在目标文件的第一列中写作,这是默认文件。

例子:'咖啡店',1

Numeric precision to use in writing data to the file, specified as the comma-separated pair consisting of'precision'以及标量或C风格格式指定符%, such as'%10.5F'. If the value of精确是标量,然后指示重要数字的数量。

例子:“精确”,3

例子:“精度”,'%10.5F'

Data Types:single|double|int8|INT16|INT32|int64|uint8|UINT16|uint32|uint64|char

线终结者,指定为逗号分隔对'newline'两者'pc'使用托架返回/线供稿(CR/LF), or'unix'使用线供稿(如果).

例子:'newline','pc'

提示

  • dlmwrite写一个电子表格程序可以读取的文件。或者,如果您的系统具有Excel®对于Windows®installed, you can create a spreadsheet usingxlswrite.

在R2006a之前引入

这个话题有帮助吗?