Two things:
fwrite(fid, uint8(inertial_data), 'uint8')
This does not write just one sample, but all the samples.
More importantly, if your inertial_data is indeed 24 bytes (stored as what? uint32?), then teh above uint8() call will map any value above 255 to 255. You should either:
- not convert the inertial_data. fwrite write it as bytes (uint8) anyway. The only thing you need to be wary off is endianness issues. You can specify the endianness in the call to fopen, or in fwrite.
fwrite(fid, inertial_data)
- convert to uint8 with typecast. This is only useful if you want to keep the data as uint8 for further processing as the above is simpler for just writing:
inertial_data_as_uint8 = typecast(inertial_data, 'uint8');
fwrite(fid, inertial_data_as_uint8);
To see the difference between uint8 and typecast, try the following:
uint8(uint32(512))
typecast(uint32(512), 'uint8')
Best Answer