Advanced File Input and output:
Where 'format' involves the conversion characters much like those used in the fprintf function. For illustration, to read the file 'subjexp.dat' just shown, we can do the following (again, for ease, omitting the error-check of fopen & fclose):
>> fid = fopen('subjexp.dat');
>> subjdata = textscan(fid,'%f %c');
The format string '%f %c' identifies that on each line there is a double value followed by the space followed by the character. This generates a 1 × 2 cell array variable known as the subjdata. The initial element in this cell array is a column vector of doubles (the initial column from the file); the next element is a column vector of characters (the next column from the file), as shown here:
[5x1 double] [5x1 char]
To refer to separate values from the vector, it is essential to index into the cell array by using curly braces and then index into the vector by using the parentheses.