Reading scientific notation tab delimited text file in MATLAB
-
19-06-2021 - |
Domanda
Is there a built-in function that can read scientific notation from a tab delimited text file in MATLAB?
A line of data looks like:
-1.52E-01 -1.32E-01 7.20E-02 -6.78E-04 1.97E-04 -1.89E-03 0.00E+00
I've tried tdfread(filename, delimiter)
without success.
Soluzione
The command you are looking for is dlmread
.
Here is the help entry from GNU Octave which should behave similarly :
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.
Altri suggerimenti
you may also try :
fid = fopen('yourfile.dat','rt');
a = fscanf(fid,'%e');
fclose(fid);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow