fread does not return the required length of data for large file.
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
raym
am 6 Mär. 2021
Beantwortet: Walter Roberson
am 6 Mär. 2021
Hi I aim to read a region of data from a large file in binary mode, but the returned vector is of wrong length.
% a file of 3GB
aRefGenomeFaFile = 'F:\GWAS\hg19.fa';
fid = fopen(aRefGenomeFaFile,'rb+');
% read a region of 1070 bytes that skips the first 249250621 bytes
a = fread(fid,[1,1070],'uint8',249250621);
% result: a is 1x13 double, not the expected length of 1070
% try another skip length 49250621
fid = fopen(aRefGenomeFaFile,'rb+');
a = fread(fid,[1,1070],'uint8',49250621);
%result: a is 1x64 double, not the expected length of 1070
Is there something wrong with reading?
Thanks
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 6 Mär. 2021
% read a region of 1070 bytes that skips the first 249250621 bytes
a = fread(fid,[1,1070],'uint8',249250621);
Nooo! That means to skip that many bytes between every value! Such as you might use if you were reading rows of a 249250621 by 1070 matrix!
Ifyou want to skip to a starting position then fseek() that many bytes relative to 'bof' and do not use a skip on the fread
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Behavior and Psychophysics finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!