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

frewind — Rewind file position indicators in MATLAB and RunMat.

frewind(fid) resets the file position indicator to the beginning of the file associated with fid. It is equivalent to fseek(fid, 0, 'bof') and follows MATLAB and RunMat status/error semantics.

Syntax

frewind(fid)

Inputs

NameTypeRequiredDefaultDescription
fidNumericScalarYes—File identifier opened by fopen.

Errors

IdentifierWhenMessage
RunMat:frewind:InvalidInputInput identifier is malformed or out of range.frewind: invalid input arguments
RunMat:frewind:InvalidIdentifierIdentifier does not refer to an open file handle.frewind: invalid file identifier. Use fopen to generate a valid file ID.
RunMat:frewind:IoFailureUnderlying seek/rewind operation fails.frewind: file I/O failed
—Internal runtime control-flow or conversion failed.frewind: internal error

How frewind works

  • frewind(fid) rewinds the file position indicator to byte offset 0 for the file identified by fid.
  • The compatibility target documents a double fid returned by fopen. Typed integer, single, logical, and provider-resident identifiers are independently gated RunMat extensions and invalid identifiers raise an error.
  • Standard input/output identifiers (0, 1, 2) are silently accepted and treated as a no-op; RunMat does not support seeking on those streams.
  • frewind produces no output value. Assigning the result of frewind to a variable yields an empty output list.
  • After frewind, subsequent calls to fread, fgets, or fscanf start from the beginning of the file.

Does RunMat run frewind on the GPU?

frewind is a host-only operation. Typed integer, single, logical, and provider-resident identifiers are classified and gated before gather; file handles always remain on the CPU and there are no provider hooks or fusion paths.

GPU memory and residency

File identifiers are owned by the host registry. In runmat compatibility mode, a provider-resident identifier is an explicitly gated extension that gathers before the seek; the rewind operation itself always executes on the host.

Examples

Write then rewind and read back binary data

fid = fopen('data.bin', 'w+b');
fwrite(fid, [1 2 3], 'double');
frewind(fid);
values = fread(fid, 'double');
fclose(fid);
delete('data.bin')

Read a text file twice without reopening

fid = fopen('notes.txt', 'r');
first_line = fgets(fid);
frewind(fid);
same_line = fgets(fid);
fclose(fid)

Rewind a binary file opened for reading bytes

fid = fopen('payload.bin', 'w+b');
fwrite(fid, uint8(1:6), 'uint8');
frewind(fid);
bytes = fread(fid, 4, 'uint8');
fclose(fid);
delete('payload.bin')

Using frewind with coding agents

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

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

FAQ

What kind of input does frewind accept?⌄

Pass a scalar numeric file identifier returned by fopen. The identifier must be a non-negative integer. Character vectors and strings are not accepted.

Does frewind return a value?⌄

No. frewind is a void function and produces no output. Capturing its result assigns an empty output list.

How does frewind compare to fseek?⌄

frewind(fid) is exactly equivalent to fseek(fid, 0, 'bof'). Use frewind when you only ever need to return to the beginning; use fseek when you need to jump to arbitrary positions.

Can I call frewind on a write-only file?⌄

Yes, as long as the underlying file was opened with a mode that supports seeking (e.g. 'w+' or 'w+b'). Rewinding a write-only stream positions the cursor at the start so subsequent writes overwrite from the beginning.

Can I call frewind on a closed file?⌄

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

Related Io functions

Filetext

fclose · feof · fgetl · fgets · fileread · filewrite · fopen · fprintf · fread · 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 frewind is executed, line by line, in Rust.

  • View the source for frewind 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
  • Errors
  • How frewind works
  • Does RunMat run frewind on the GPU?
  • GPU memory and residency
  • Examples
  • Write then rewind and read back binary data
  • Read a text file twice without reopening
  • Rewind a binary file opened for reading bytes
  • Using frewind 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