是否有内置函数可以从 MATLAB 中的制表符分隔的文本文件中读取科学记数法?
一行数据如下所示:
-1.52E-01 -1.32E-01 7.20E-02 -6.78E-04 1.97E-04 -1.89E-03 0.00E+00
我试过tdfread(filename, delimiter)
没有成功。
您要查找的命令是dlmread
.
这是来自 GNU Octave 的帮助条目,它的行为应该类似:
DATA = dlmread (FILE)
DATA = dlmread (FILE, SEP)
DATA = dlmread (FILE, SEP, R0, C0)
DATA = dlmread (FILE, SEP, RANGE)
DATA = dlmread (..., "emptyvalue", EMPTYVAL)
Read numeric data from the text file FILE which uses the delimiter
SEP between data values.
If SEP is not defined the separator between fields is determined
from the file itself.
The optional scalar arguments R0 and C0 define the starting row and
column of the data to be read. These values are indexed from zero,
i.e., the first data row corresponds to an index of zero.
The RANGE parameter specifies exactly which data elements are read.
The first form of the parameter is a 4-element vector containing
the upper left and lower right corners '[R0,C0,R1,C1]' where the
indices are zero-based. Alternatively, a spreadsheet style form
such as "A2..Q15" or "T1:AA5" can be used. The lowest alphabetical
index 'A' refers to the first column. The lowest row index is 1.
FILE should be a filename or a file id given by 'fopen'. In the
latter case, the file is read until end of file is reached.
The "emptyvalue" option may be used to specify the value used to
fill empty fields. The default is zero. Note that any non-numeric
values, such as text, are also replaced by the "emptyvalue".
See also: csvread, textscan, textread, dlmwrite.
你也可以试试:
fid = fopen('yourfile.dat','rt');
a = fscanf(fid,'%e');
fclose(fid);