Operation on file, MATLAB in Statistics

Operation on file:

We concentrate first on the fgetl function that reads strings from the file one line at a time. The fgetl functions afford more control over how the data is read than the other input functions. The fgetl function reads one line of data from a file into the string; string functions can be used then to manipulate the data. As fgetl reads only one line, it generally is placed in a loop which keeps going until the end of the file is reached. The function feof returns the logical true if the end of the file has been reached. The function call feof(fid) would return the logical true when the end of the file has been reached for the file specified by fid, or logical false when not. A common algorithm for reading from a file into strings would be as shown below:

  •  Try to open the file; check to make sure that the file open was successful.
  •  If opened, the loop until end of the file is reached. For each of line in the file,

-  read it into the string

- manipulate the data

  •  Try to close the file; check to make sure that the file close was successful. 

 

Posted Date: 10/20/2012 6:19:53 AM | Location : United States







Related Discussions:- Operation on file, Assignment Help, Ask Question on Operation on file, Get Answer, Expert's Help, Operation on file Discussions

Write discussion on Operation on file
Your posts are moderated
Related Questions
Input in a While Loop: The script below repeats the procedure of prompting a user, the reading in a positive number, and echo-printing it, as long as the user properly enters

Example of sorting strings: To sort a cell array of strings, also the sort function is used. The illustration is as follows, >> engcellnames = {'Chemical','Mechanical',.

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 Vectorizing: Likewise, for an operation on a matrix, a nested loop would be needed; for illustration, supposing a matrix variable mat: [r c] = size(mat); for

Example of Nested functions: For illustration, the function below computes and returns the volume of a cube. Three arguments are then passed to it, for the width and length of

Illustration of Binary search: An illustration to search for the key of 91 in the vector is as shown below: The table below shows what will happen in each iteration of

Polynomials: Simple curves are polynomials of various degrees, or orders. The degree is the integer of the highest exponent in the expression. The illustrations are as follows

fscanf function - file function: The fscanf reads matrix variable mat columnwise from the file specified by fid. The 'format' involves conversion characters much similar to th

Advanced File Input and Output: In that section, we saw how to read the values entered by user using the input as well as the output functions disp and fprintf, that shows inf

Tracing: Sometimes, when a program has loops and/or selection statements and is not running properly, it is helpful in the debugging process to know exactly which statements h