fread returns wrong array size for non-zero skip
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am having trouble using fread on a binary file. fread appears to be returning the wrong number of elements in some cases when I set a non-zero skip parameter, and array sizes greater than 1024.
That is,
>> [val,vsize] = fread(fid,[1023,1],'1023*bit12=>int16',0,'ieee-le');
and
>> [val,vsize] = fread(fid,[1023,1],'1023*bit12=>int16',8,'ieee-le');
both work as expected.
This works:
>> [val,vsize] = fread(fid,[1025,1],'1025*bit12=>int16',0,'ieee-le');
but not this:
>> [val,vsize] = fread(fid,[1025,1],'1025*bit12=>int16',8,'ieee-le');
In the latter case, vsize is 2048 and val becomes a 1024x2 array padded with 1023 zeros.
It appears that with a non-zero skip parameter, fread always returns vsize rounded upwads to the nearest 1024 (2900 is rounded upwards to 3072, 4000 to 4096 and so on), and an array padded with zeros to that length.
This becomes a major problem, as I want to read a large number of vectors in one go:
>> [val,vsize] = fread(fid,[4000,5000],'4000*bit12=>int16',352,'ieee-le');
Any ideas what is going on?
I am using R2012a (64 bit) on Windows 7.
1 Kommentar
Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!