advanced file input and outputwhere format


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');

>> fclose(fid)

 

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:

 

>> subjdata

subjdata =

    [5x1 double] [5x1 char]

>> subjdata{1}

ans =

    5.3000

    2.2000

    3.3000

    4.4000

    1.1000

>> subjdata{2}

ans =

a

b

a

a

b

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. 

Request for Solution File

Ask an Expert for Answer!!
Applications of MATLAB: advanced file input and outputwhere format
Reference No:- TGS0175125

Expected delivery within 24 Hours