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');
source share