Reading from files, MATLAB in Statistics

Reading from Files:

There are many lower level functions which read from files. The function fscanf reads the formatted data into a matrix, by using conversion formats like %s for strings, %d for integers, and %f for floats. The function textscan reads text data from a file and stores it in the cell array. The fgetl and fgets functions both read the strings from a file one line at a time; the dissimilarity is that the fgets holds the newline character when there is one at the end of the line, while the fgetl function gets rid of it. All these functions at first need opening the file, and then closing it when terminated.

As the fgetl and fgets functions read one line at a time, such functions are usually in some form of a loop. The fscanf and textscan functions can read the whole data file into one data structure. In terms of the level, these two functions are somewhat in between the load function & the lower level functions like fgetl. The file should be opened by using fopen first, and must be closed by using fclose afterward the data has been read. Though, no loop is needed; they will read in the whole file automatically but into the data structure.

 

 

Posted Date: 10/20/2012 6:18:34 AM | Location : United States







Related Discussions:- Reading from files, Assignment Help, Ask Question on Reading from files, Get Answer, Expert's Help, Reading from files Discussions

Write discussion on Reading from files
Your posts are moderated
Related Questions
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

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

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

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

Logical errors: The Logical errors are more complicated to locate, as they do not result in any error message. The logical error is a mistake in reasoning by the programmer, b

Example of Core objects: The one core graphics object is a line that is also what the plot function produces. Here is an illustration of generating a line object, altering som

Areacirc function: The areacirc function can be called from the Command Window as shown here, or from a script. Here is a script which will prompt the user for the radius of o

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

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

Example of Median For the vector [1 4 5 9 12 33], the median is the average of the 5 & 9 in the middle: >> median([1 4 5 9 12 33]) ans =     7