Documentation

tdfread

Read tab-delimited file

Syntax

tdfread
tdfread(filename)
tdfread(filename,delimiter)
s = tdfread(filename,...)

Description

tdfreaddisplays 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.tdfreadcreates 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,tdfreadcreates adoublevariable. Otherwise,tdfreadcreates acharvariable. After all values are imported,tdfreaddisplays information about the imported values using the format of thetdfreadcommand.

tdfread(filename)allows command line specification of the name of a file in the current folder, or the complete path name of any file, usingfilename.

tdfread(filename,delimiter)indicates that the character specified bydelimiterseparates columns in the file. Accepted values fordelimiterare:

  • ' 'or'space'

  • '\t'or'tab'

  • ','or'comma'

  • ';'or'semi'

  • '|'or'bar'

The default delimiter is'tab'.

s = tdfread(filename,...)returns a scalar structureswhose 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, andTestfrom the filesat2.datand 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

See Also

|

Introduced before R2006a

Was this topic helpful?