frewind

Moves the read position of a file back to its beginning.

Category: Data Import and Analysis > Data Import and Export

Syntax

frewind(fid)

Sets the file position to the first byte.

Description

frewind is shorthand for fseek(fid, 0, 'bof'). It also clears the end-of-file indicator, so a file that has been read to the end can be read again.

Input arguments

fid
File identifier from fopen.

Example

Read twice

fid = fopen('r.txt', 'w'); fprintf(fid, 'abc'); fclose(fid);
fid = fopen('r.txt');
s1 = fread(fid, Inf, '*char')'
feof(fid)
frewind(fid);
s2 = fread(fid, 2, '*char')'
ftell(fid)
fclose(fid);
Output
s1 = 'abc'
ans = 1
s2 = 'ab'
ans = 2

See also

fseek ftell feof fopen