Reputation: 7458
In the code below I am expecting the file size to be 4096 bytes (4kb) right? But in practice the file size becomes 1024 bytes (1kb)! I don't understand why?
fid = fopen('test.test', 'w', 'b');
buff= zeros(1024,1,'int32');
fwrite(fid,buff);
fclose(fid);
Upvotes: 4
Views: 369
Reputation: 125874
The problem is that FWRITE, by default, writes data out as 'uint8'
type (i.e. one quarter the size of an 'int32'
). It doesn't automatically detect the type of the data passed to it, so you need to specify the type for the output in the call to FWRITE, like so:
fwrite(fid, buff, 'int32');
Upvotes: 2