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
Print an imaginary number: To print an imaginary number, the function disp will show both parts automatically: >> disp(z1)    4.0000 + 2.0000i The function fprint

Functions to create special matrices: The MATLAB also has various functions which create special matrices. For illustration, the zeros function generates a matrix of all zeros

Plot types: Besides plot and bar, there are another plot types like stem plots, histograms, stem plots, area plots and pie charts, and also other functions which customize the

Find Minimum and Maximum for each row To find the maximum (or minimum) for each row, the dimension of 2 (that is how a MATLAB refers to rows) can be identified as the third arg

Pie chart - plot functions: The MATLAB also has a function pie which will generate a pie chart. Calling the function with the form pie (vec) draws a pie chart, by using the pe

Complex numbers: A complex number is commonly written in the form z = a + bi here a is known as the real part of the number z, b be the imaginary part of z, and i is √-1

Nested IF-ELSE statements: The if-else statement is used to select between the two statements. In order to select from more than two statements, the if-else statements can als

Fliplr function: The fliplr function "flips" the matrix from left to right (in another words the left-most column, the first column, become the last column and so on), and the

Built in recursive function in MATLAB: We have seen that the built-in function in MATLAB to compute factorials, termed as the factorial and we know how to implement the iterat

Illustrations of Variable number of output arguments: In the illustrations shown here, the user should actually know the type of the argument in order to establish how many va