4

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);  
1

1 Answer 1

2

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');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.