MATLAB: Can’t 32-bit values be converted to 24-bit values

typecast

I have an array with 5 columns of data points and I need to convert the points from 32-bit to 24-bit. The cast or typecast functions don't support 'bit24' as the precision value.
Is there another way to do this? I also tried writing the values into a new binary file and writing them back out at 24-bit, but it writes them out as a double.

Best Answer

MATLAB does not have any 24 bit data type.
typecast() is only for taking a block of memory and changing the interpretation of the block without altering any of the values -- for example, taking a pair of unsigned 8 bit integers and re-interpeting it as a signed 16 bit integer.
Are your values 24 bit signed integers that have been packed into 32 bit unsigned integers, four 24 bit values (96 bits) packed into 3 uint32 (96 bits) ? If so then what byte order has been used? An additional byte will need to be provided for each, and possibly bytes will need to be re-arranged. In my experience, 24 bit values are typically stored MSB first, which is not how bytes are arranged in any current release of MATLAB.
Related Question