textread

Returns result R after reading a formatted data from a file, f, specified by an optional template, t.

Syntax

[R, ...] = textread(f,...)

[R, ...] = textread(f, t, ...)

[R, ...] = textread(f, t, 'headerlines', linestoskip, ...)

[R, ...] = textread(f, t, 'headerlines', linestoskip, 'delimiter', delim)

Inputs

f
Any file name or a valid file stream.
Type: string | int
t
Template to read formatted data from s. Valid formats are '%d', '%f', '%g and '%s'.
Type: string
linestoskip (optional)
Name-value pair which the number of lines to skip since the start of the file f. Valid values are finite, positive integers.
Type: Finite, positive integer
delim (optional)
Name-value pair which specifies the delimiter. If nothing is specified, whitespace is used as the delimiter.
Type: string

Outputs

R
Type: cell

Examples

Reads all (float) data from the given file. Data in the file is 1 2 3 4 5 6 7 8 9

[A, B, C] = textread('Filemanipulation/textreadFile.txt')


  A = [Matrix] 3 x 1
  1
  4
  7
  B = [Matrix] 3 x 1
  2
  5
  8
  C = [Matrix] 3 x 1
  3
  6
  9

Specifies header lines while reading formatted data. Data in the file is % names of the columns A B C year1 100 200 300 year22 44 55 66 year333 7 8 9:

[A, B, C, D] = textread('Filemanipulation/textreadFile2.txt','%s %f %f %f','headerlines',1)


  A =
  {
  [1,1] year1
  [2,1] year22
  [3,1] year333
  }
  B = [Matrix] 3 x 1
  100
   44
    7
  C = [Matrix] 3 x 1
  200
   55
    8
  D = [Matrix] 3 x 1
  300
   66
    9

Specifies header lines and delimiter while reading formatted data. Data in the file is % names of the columns A B C year1,100,200,300 year22,44,55,66 year333,7,8,9:

[A, B, C, D] = textread('Filemanipulation/textreadFile3.txt','%s %f %f %f', 'delimiter', ',', 'headerlines', 1)
       

  A =
  {
  [1,1] year1
  [2,1] year22
  [3,1] year333
  }
  B = [Matrix] 3 x 1
  100
   44
    7
  C = [Matrix] 3 x 1
  200
   55
    8
  D = [Matrix] 3 x 1
  300
   66
    9

Comments

If no templates are specified, the data read will be of type float. The optional name-value pair 'headerlines', linestoskip, can specify the number of lines to skip from the start of the file. The optional name-value pair 'delimiter', delim, can specify delimiter while reading the data. If no delimiters are specified, whitespace is used as the default delimiter.