Advanced file input and output, MATLAB in Statistics

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. 

Posted Date: 10/20/2012 6:26:55 AM | Location : United States







Related Discussions:- Advanced file input and output, Assignment Help, Ask Question on Advanced file input and output, Get Answer, Expert's Help, Advanced file input and output Discussions

Write discussion on Advanced file input and output
Your posts are moderated
Related Questions
Example of Function stubs: The three functions have not so far been written, though, therefore the function stubs are put in place so that the script can be executed and teste

Statistics There are numerous statistical analyses which can be executed on data sets. In MATLAB software, the statistical functions are in the data analysis help topic known a

Illustration of Indexing into vectors of structures: For illustration, the function to print the information from packages has been modified therefore in addition to the vecto

Areacirc function: The areacirc function can be called from the Command Window as shown here, or from a script. Here is a script which will prompt the user for the radius of o

Vectors of nested structures: The Combining vectors and nested structures are possible to have a vector of structures in which several fields are structures themselves. Here i

Nested for Loops: The action of a loop can be any of the valid statement(s). Whenever the action of a loop is the other loop, this is known as nested loop. As an illustrati

Illustration of tracing a error: The one way of following the flow of function, or tracing it, is to use the echo function. The echo function, that is a toggle, will show each

Example of Median For the vector [1 4 5 9 12 33], the median is the average of the 5 & 9 in the middle: >> median([1 4 5 9 12 33]) ans =     7

Lower Level File I/O Functions: Whenever reading from data file, as long as the data in the file is "regular" the load function works-in another words, the similar type of dat

Illustration of Mode When there is more than one value with similar (highest) frequency, then the smaller value is mode. In the case below, as 3 and 8 appear twice in the vecto