Illustration of advanced file input and output, MATLAB in Mathematics

Illustration of Advanced file input and output:

For illustration, to refer to the third number in the first element of the cell array:

>> subjdata{1}(3)

ans =

   3.3000

 

The script which reads in this data and echo-prints it is shown here:

1007_Illustration of Advanced file input and output.png

Executing this script generates the following results which are as shown below:

>> textscanex

5.3 a

2.2 b

3.3 a

4.4 a

1.1 b

File close successful

To conclude, we know four techniques of reading from a file. The function load will only work when the values in the file are all of similar type and there is similar number on every line in the file, so that they can be read into the matrix. If this is not the situation, lower level functions should be used. To use these, the file should be opened first and then closed whenever the reading has been done. The fscanf function will read into the matrix, converting the characters to their ASCII equivalents. The textscan function will rather read into a cell array which stores each column from the file into individual column vectors of the cell array. At last, the fgetl function can be used in a loop to read each line from the file as an individual string; the string manipulating functions should then be used to break the string into pieces and convert to numbers.

Posted Date: 10/20/2012 6:29:01 AM | Location : United States







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

Write discussion on Illustration of advanced file input and output
Your posts are moderated
Related Questions
Illustration of Spreadsheet Files: This reads the numbers in a double vector variable nums and the text in a cell array txt (the xlsread function forever returns the numbers f

Illustration of Advanced file input and output: For illustration, to refer to the third number in the first element of the cell array: >> subjdata{1}(3) ans =

Types of User-defined Functions: We know how to write a user-defined function, stored in an M-file, which computes and returns one value. This is merely one type of the functi

Counting in a While Loop: Whenever it is not known ahead of the time how many values will be entered into the script, it is often essential to count the number of values which

Creating Customized strings: There are many built-in functions which create customized strings, including blanks, char, and sprintf. We know that the char function can be u

Illustration of Variance For illustration, for the vector [4, 6, 1, 5], there are n = 4 values therefore n - 1 is 3. The mean of this data set is also 4. The variance will be

Illustration of Minimum and Maximum Value Both of these functions also return the index of the minimum or maximum value; when there is more than one occurrence, it returns the

Common form of the switch statement: The common form of the switch statement is as shown below:   switch switch_expression   case caseexp1    action1   case cas

Give the formula for a rational function that has a hole at x=7 & vertical asmptote at x=-3/2

sprintf function: The sprintf function works precisely like the fprintf function, but rather than printing it generates a string. Here are some illustrations in which the outp