Tab-delimited Files

Sometimes the file includes both text and numbers so the commands load and fscanf don't work. In this case, MATLAB provides other choices for file input, like caseread, tblread, and the one we are going to use here, tdfread.

Basically, tdfread means it reads Tab-Delimited Files, and the files must have variable names in the first row. The syntax is simple: (you can use whatever you want to substitute for myCluster; typically we use the file name or object name, like ngc188)

myCluster = tdfread('ngc188.txt')
myCluster = 

           MAIN_ID: [1977x21 char]
             OTYPE: [1977x5 char]
                RA: [1977x3 double]
               DEC: [1977x3 double]
      COO_ERR_MAJA: [1977x1 double]
      COO_ERR_MINA: [1977x1 double]
     COO_ERR_ANGLE: [1977x1 double]
              PMRA: [1977x1 double]
             PMDEC: [1977x1 double]
                 B: [1977x1 double]
                 V: [1977x1 double]
                 R: [1977x1 double]
                 J: [1977x1 double]
                 H: [1977x1 double]
                 K: [1977x1 double]
           SP_TYPE: [1977x8 char]
    GALDIM_MAJAXIS: [1977x1 double]
    GALDIM_MINAXIS: [1977x1 double]
      GALDIM_ANGLE: [1977x1 double]
           BIBLIST: [1977x1 double]

As you can see, tdfread creates a structure myCluster, which contains fields from each column of the file ngc188.txt, named after the first row. More importantly, tdfread can automatically decide the type of variables (double, char, etc.) based on the data in the second and following rows.

For example, the field myCluster.MAIN_ID is a char array: (recall the syntax s.a means field a of structure s)

myCluster.MAIN_ID
ans =

Cl* NGC 188 FTS 5    
Cl* NGC 188 FTS 1    
Cl* NGC 188 FTS 6    
Cl* NGC 188 FTS 7    
Cl* NGC 188 FTS 29   
Cl* NGC 188 FTS 20   

... ...

and the variable myCluster.B is a numeric vector:

myCluster.B
ans =

   13.5900
   13.0700
   13.4900
   13.7900
   14.7900
   14.7300
   
   ... ...

Note that NaN means "not a number"; when you see this in myCluster.B means we are missing the B-band data from some objects.

In fact, tdfread can also read files with other delimiters. To read the file cluster1.dat (you can find it on the website) which uses comma to separate columns, just add ',' or 'comma' to specify the delimiter:

myCluster2 = tdfread('cluster1.dat',',')
myCluster2 = 

     objid: [1180x1 double]
       run: [1180x1 double]
     rerun: [1180x1 double]
    camcol: [1180x1 double]
     field: [1180x1 double]
       obj: [1180x1 double]
      type: [1180x1 double]
        ra: [1180x1 double]
       dec: [1180x1 double]
         u: [1180x1 double]
         g: [1180x1 double]
         r: [1180x1 double]
         i: [1180x1 double]
         z: [1180x1 double]
     Err_u: [1180x1 double]
     Err_g: [1180x1 double]
     Err_r: [1180x1 double]
     Err_i: [1180x1 double]
     Err_z: [1180x1 double]

Other accepted values for delimiter include ' ' or 'space', ';' or 'semi', and '|' or 'bar'.