MATLAB array int32 and write to file

In the code below, I expect the file size to be 4096 bytes (4kb)? But in practice, the file size is 1024 bytes (1kb)! I do not understand why?

fid = fopen('test.test', 'w', 'b'); buff= zeros(1024,1,'int32'); fwrite(fid,buff); fclose(fid); 
+4
source share
1 answer

The problem is that FWRITE by default writes data as a 'uint8' type (i.e., a quarter times the size of 'int32' ). It does not automatically determine the type of data passed to it, so you need to specify the type of output in the FWRITE call, for example:

 fwrite(fid, buff, 'int32'); 
+2
source

Source: https://habr.com/ru/post/1398279/


All Articles