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
Need of a nested loop: How would we sum each individual column, rather than getting an overall sum? Answer: The programming technique would need a nested loop in whi

Illustration of Median When the vector is not in sorted order to start with, the median function will still return the right answer (it will sort the vector automatically). For

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

Functions which complete a task without returning Values: Most of the functions do not compute values, but instead of accomplish a task like printing formatted output. As thes

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

Rectangle - graphics objects: The other core graphics object is the rectangle that can have curvature added to it (!!). Merely calling the function rectangle without any argum

MENU Function: The MATLAB also has a built-in function known as menu which will display a figure Window with push buttons for the choices. The very first string passed to the

Function polyval - interpolation: The function polyval can then be used to compute the polynomial at particular values. For illustration, we could compute at every value in th

Vectorizing: In most of the cases in MATLAB, loops are not essential. As MATLAB is written specifically to work with the vectors and matrices, most operations can be completed

Example of customizing plots: As the other illustration of customizing plots, the pieces of a pie chart can be "exploded" from the rest. In this situation, the two vectors are