【转】matab中dlmread 和dlmwrite函数的具体应用

转自:http://www.ymlib.net/article/sort010/info-376.html

 

matab中dlmread 和dlmwrite函数的基本格式:
M = dlmread(filename, delimiter, R, C)
M = dlmread(filename, delimiter, range)
range = [R1 C1 R2 C2] where (R1,C1) is the upper left corner of the data to be read and (R2,C2) is the lower right corner. You can also specify the range using spreadsheet notation, as in range = 'A1..B7'.
示例:



dlmwrite: Write matrix to ASCII-delimited file

1、定义输出格式: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.
属性定义:
delimiter(分割符): Delimiter string to be used in separating matrix elements.
newline(断行符):Character(s) to use in terminating each line.
(1) 'pc': PC terminator (implies carriage return/line feed (CR/LF))
(2) 'unix': UNIX terminator (implies line feed (LF))
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(输出精度): Specify the number of significant digits or a C-style format string starting in %, such as '%10.5f'.
示例:
dlmwrite('data.txt', data, 'precision', '%10.6f', 'roffset', 10, 'coffset', 10, 'delimiter', ';', 'newline', 'pc');


2、追加方式输出:dlmwrite(filename, M, '-append', attribute-value list) appends the matrix to the file. If you do not specify '-append', dlmwrite overwrites any existing data in the file. You can place the '-append' flag in the argument list anywhere between attribute-value pairs, but not in between an attribute and its value.
 

posted on 2011-09-14 04:25  风在竹林  阅读(1597)  评论(0编辑  收藏  举报