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
Mode The mode of a data set is the value which appears most often. The built-in function in a MATLAB for this is known as the mode. >> x = [9 10 10 9 8 7 3 10 9 8 5 10];

Graphics objects: The objects involve graphics primitives like lines and text, and also the axes used to orient the objects. These objects are organized hierarchically, and the

Sequential Search: A sequential search is completed by looping through the vector element-by-element starting from the beginning, looking for the key. Usually the index of the

Illustration of reading from files: For illustration, suppose that there is a data file 'subjexp.dat' that has on each line a number followed by thecharacter code. The type fu

WHILE Loops: The while statement is used as a conditional loop in MATLAB; it is used to repeat an action whenever ahead of the time it is not known how many times the action w

Function Stubs: The other common debugging method, which is used when there is a script main program which calls many functions, is to use the function stubs. A function stub

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

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

Persistent Variables: Generally, whenever a function stops executing, then the local variables from that function are cleared. That means that each and every time a function i

Illustration of Nested loops: Running the script shows the output: >> printstars ***** ***** ***** The variable rows identifies the number of rows to print, and