フィルターのクリア

Offset must be a double error when reading file byte by byte

2 ビュー (過去 30 日間)
Lev Mihailov
Lev Mihailov 2022 年 2 月 15 日
コメント済み: Jan 2022 年 2 月 16 日
I read the file byte by byte, I know the byte structure, the small end is 220,400,600,1000 and then 1220,1620... bytes, all values are uint16, I need to get a matrix for each byte order, i.e. 220:N, 420:N (N is the length of the file)
fid=fopen(fileName,'rb') % opens the file for reading
x1 = fread(fid, Inf, 'uint8', 220);
fseek(fid, 'bof', 220);
x2 = fread(fid, Inf, 'uint8', 400);
fseek(fid, 'bof', 620);
x3 = fread(fid, Inf, 'uint8', 600);
fseek(fid, 'bof', 1020);
x4 = fread(fid, Inf, 'uint8', 1000);
fclose(fid);
Error using fseek
Offset must be a double.
Error in Untitled3 (line 27)
fseek(fid, 'bof', 220);
  2 件のコメント
Jan
Jan 2022 年 2 月 15 日
By the way, specifying the 'b' format in FOPEN is outdated for over 20 years.
The problem looks strange. If the opening of the file fails, another message is shown. Are you using the standard function fseek() of Matlab? What is the output of:
which fseek -all
Lev Mihailov
Lev Mihailov 2022 年 2 月 15 日
Yes, I use the standard function, the code is presented, it’s just a task to read the file byte by byte, the structure is very convenient, but for some reason it’s impossible to read 400, 600 and 1000 bytes of information

サインインしてコメントする。

回答 (1 件)

Voss
Voss 2022 年 2 月 15 日
I think you've got the second and third inputs to fseek() swapped around. It should be fseek(fileID,offset,origin), so for instance:
fseek(fid, 220, 'bof');

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by