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
Roots function - Polynomials: The roots function in MATLAB is used to find the roots of an equation represented by a polynomial. For illustration, for the mathematical functio

Generic code for Reading from Files: The generic code to complete this is as shown below:   fid = fopen('filename'); if fid == -1    disp('File open not suc

Types of errors: There are some various kinds of errors which can occur in a program, that fall into the categories of run-time errors, syntax errors, and logical errors. T

Opening and Closing a File: The Files are opened with the fopen function. By the default, fopen function opens a file for reading. If the other mode is preferred, a permission

Vectors of nested structures: The Combining vectors and nested structures are possible to have a vector of structures in which several fields are structures themselves. Here i

Illustration of nested for loops and the if statements: For illustration,when the file contains: 33   -11  2  4      5   9 22     5  -7  2     11    3 the outco

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

function sortrows - sorting strings: The function sortrows sorts each and every row as a block, or group, and it also will work on numbers. Here in this illustration the rows

Median The median is defined only for a data set which has been sorted first, that means that the values are in order. The median of a sorted set of data values (n) is defined

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];