RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact
  • License
  • Privacy

Learn

  • Docs
  • Blog
  • Benchmarks
  • RunMat vs MATLAB Online

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

/
See all docs
Builtin Reference
    • fclose
    • feof
    • fgetl
    • fgets
    • fileread
    • filewrite
    • fopen
    • fprintf
    • fread
    • frewind
    • fwrite
    • readlines
    • writelines

feof — Query end-of-file state for file identifiers in MATLAB and RunMat.

feof(fid) reports the end-of-file indicator associated with the open file identified by fid. It returns a logical scalar. Opening a file initializes the indicator to false; a read that encounters end-of-file sets it, and successful repositioning clears it.

Syntax

tf = feof(fid)

Inputs

NameTypeRequiredDefaultDescription
fidNumericScalarYes—File identifier opened by fopen.

Returns

NameTypeDescription
tfLogicalArrayTrue when positioned at end-of-file.

Errors

IdentifierWhenMessage
RunMat:feof:InvalidInputInput identifier is malformed or out of range.feof: invalid file identifier input
RunMat:feof:InvalidIdentifierIdentifier does not refer to an open file handle.feof: invalid file identifier. Use fopen to generate a valid file ID.
—Internal control-flow conversion failed.feof: internal error

How feof works

  • tf = feof(fid) returns logical 1 only after a prior read on that open file encountered end-of-file; merely reaching the exact final byte does not set the indicator.
  • The MATLAB-compatible identifier form is a finite integer-valued double scalar returned by fopen, checked against the runtime i32 identifier range before registry access.
  • Typed integer identifiers across all eight built-in integer classes, logical identifiers, and provider-resident identifiers are three independently gated RunMat extensions. Compatibility preflight occurs before provider gathering or registry access.
  • Standard input/output identifiers (0, 1, 2) always report false because RunMat does not yet expose end-of-file state for those streams.
  • feof only queries registry state: it does not seek, inspect file length, contact a provider after host conversion, or modify the file position.
  • A newly opened empty file reports false. The first read attempt that encounters end-of-file sets the indicator to true.
  • frewind and other successful positioning operations clear the end-of-file indicator. Closing the file removes its state with the registry entry.
  • The compatibility classification is grounded in the linked public documentation and remains evidence-open for additional release-specific findings.

Does RunMat run feof on the GPU?

feof is a host-only state query with no provider hooks or fusion path. In RunMat extension mode, a resident identifier is compatibility-gated before gathering; the resulting host scalar is range-checked before the registry is queried. The result is always a host logical scalar.

GPU memory and residency

No. File handles and end-of-file state are owned by the host registry. A provider-resident scalar identifier is a gated RunMat extension; compatibility preflight runs before the provider is contacted, then the scalar is gathered for exact identifier validation and the host registry query.

Examples

Check for end-of-file while reading line by line

[fid, msg] = fopen('log.txt', 'r');
assert(fid ~= -1, msg);
while ~feof(fid)
    line = fgets(fid);
    disp(line);
end
fclose(fid)

Detect the end of a binary stream read with fread

[fid, msg] = fopen('payload.bin', 'rb');
assert(fid ~= -1, msg);
while ~feof(fid)
    chunk = fread(fid, 1024, 'uint8');
    process(chunk);
end
fclose(fid)

Observe read-driven state for an empty file

[fid, msg] = fopen('empty.txt', 'r');
assert(fid ~= -1, msg);
assert(~feof(fid));
fgets(fid);            % encounters end-of-file
assert(feof(fid));
frewind(fid);
assert(~feof(fid));
fclose(fid)

Protect against invalid identifiers

try
    feof(9999);
catch err
    disp(err.message);
end

Checking end-of-file with typed and resident identifiers

fid = gpuArray(int32(fopen('samples.dat', 'rb')));
tf = feof(fid);        % resident and typed-integer extension gates apply before gathering

Using feof with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how feof changes the result.

Run a small feof example, explain the result, then change one input and compare the output.

FAQ

What kind of input does feof accept?⌄

The MATLAB-compatible form is a finite integer-valued double scalar returned by fopen. RunMat mode can additionally enable typed integer, logical, and provider-resident identifier extensions. Character vectors and strings are not accepted.

Does feof move the file position indicator?⌄

No. The builtin reads the registry's end-of-file flag and performs no seek or length query, so subsequent reads resume exactly where they left off.

How does feof behave for standard input/output?⌄

RunMat currently reports false for identifiers 0, 1, and 2 because the standard streams are not integrated with the file registry. Use other platform APIs to detect end-of-file on those streams if necessary.

Does feof require a previous read attempt to return true?⌄

Yes. Reaching the exact end position is not sufficient. A read operation must attempt to read at end-of-file; successful repositioning such as frewind clears the flag.

Can I call feof on closed files?⌄

No. Passing a closed or never-opened identifier raises "Invalid file identifier. Use fopen to generate a valid file ID."

How does feof interact with GPU execution?⌄

feof itself never runs on the GPU. When the identifier is stored in a GPU array, the runtime gathers it before performing the host-only check.

Related Io functions

Filetext

fclose · fgetl · fgets · fileread · filewrite · fopen · fprintf · fread · frewind · fwrite · readlines · writelines

Net

accept · read · readline · tcpclient · tcpserver · write

Repl Fs

addpath · cd · copyfile · delete · dir · exist · fileattrib · fileparts · fullfile · genpath · getenv · getpref · isenv · isfile · isfolder · ispref · ls · matlabroot · memmapfile · mkdir · movefile · open · opentoline · path · pathsep · pcode · pwd · readstruct · rehash · restoredefaultpath · rmdir · rmpath · run · savepath · setenv · setpref · system · tempdir · tempname · uigetdir · uigetfile · uiputfile · unsetenv · userpath · what · winqueryreg · xmlread · xmlwrite

Tabular

arrayDatastore · csvread · csvwrite · detectImportOptions · dlmread · dlmwrite · fileDatastore · parquetDatastore · parquetinfo · parquetread · readcell · readmatrix · readtable · readtimetable · spreadsheetImportOptions · writecell · writematrix · writetable · writetimetable · xlsread · xlswrite

Audio

audioinfo · audioread

Io

clc · diary · disp · display · format · input

Archive

gunzip · gzip · unzip

Hdf5

h5disp · h5info · h5read · h5write · h5writeatt · hdf5info · hdf5read · hdf5write

Import

importdata · textscan

Json

jsondecode · jsonencode

Mat

load · matfile · save

Http

sendmail · urldecode · urlencode · weboptions · webread · websave · webwrite

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how feof is executed, line by line, in Rust.

  • View the source for feof in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How feof works
  • Does RunMat run feof on the GPU?
  • GPU memory and residency
  • Examples
  • Check for end-of-file while reading line by line
  • Detect the end of a binary stream read with fread
  • Observe read-driven state for an empty file
  • Protect against invalid identifiers
  • Checking end-of-file with typed and resident identifiers
  • Using feof with coding agents
  • FAQ
  • Related Io functions
  • Filetext
  • Net
  • Repl Fs
  • Tabular
  • Audio
  • Io
  • Archive
  • Hdf5
  • Import
  • Json
  • Mat
  • Http
  • Open-source implementation
  • About RunMat