tdfread
Read tab-delimited file
Syntax
tdfread
tdfread(filename
)
tdfread(filename
,delimiter
)
s = tdfread(filename
,...)
Description
tdfread
displays theFile Opendialog box for interactive selection of a data file, then reads data from the file. The file should have variable names separated by tabs in the first row, and data values separated by tabs in the remaining rows.tdfread
creates variables in the workspace, one for each column of the file. The variable names are taken from the first row of the file. If a column of the file contains only numeric data in the second and following rows,tdfread
creates adouble
variable. Otherwise,tdfread
creates achar
variable. After all values are imported,tdfread
displays information about the imported values using the format of thetdfread
command.
tdfread(
allows command line specification of the name of a file in the current folder, or the complete path name of any file, usingfilename
)filename
.
tdfread(
indicates that the character specified byfilename
,delimiter
)delimiter
separates columns in the file. Accepted values fordelimiter
are:
' '
or'space'
'\t'
or'tab'
','
or'comma'
';'
or'semi'
'|'
or'bar'
The default delimiter is'tab'
.
s = tdfread(
returns a scalar structurefilename
,...)s
whose fields each contain a variable.
Examples
The following displays the contents of the filesat2.dat
:
type sat2.dat Test,Gender,Score Verbal,Male,470 Verbal,Female,530 Quantitative,Male,520 Quantitative,Female,480
The following creates the variablesGender
,Score
, andTest
from the filesat2.dat
and displays the contents of the MATLAB®workspace:
tdfread('sat2.dat',',') Name Size Bytes Class Attributes Gender 4x6 48 char Score 4x1 32 double Test 4x12 96 char