FEOF End Of File Function

Section: Input/Ouput Functions

Usage

Check to see if we are at the end of the file. The usage is
  b = feof(handle)

The handle argument must be a valid and active file handle. The return is true (logical 1) if the current position is at the end of the file, and false (logical 0) otherwise. Note that simply reading to the end of a file will not cause feof to return true. You must read past the end of the file (which will cause an error anyway). See the example for more details.

Example

Here, we read to the end of the file to demonstrate how feof works. At first pass, we force a read of the contents of the file by specifying inf for the dimension of the array to read. We then test the end of file, and somewhat counter-intuitively, the answer is false. We then attempt to read past the end of the file, which causes an error. An feof test now returns the expected value of true.
--> fp = fopen('test.dat','rb');
--> x = fread(fp,[512,inf],'float');
--> feof(fp)

ans = 
 1 

--> x = fread(fp,[1,1],'float');
--> feof(fp)

ans = 
 1