MATLAB: Does an array of doubles stored as blobs in a Database table truncated to 8-bit integers when fetched using Database Toolbox

Database Toolbox

I am storing an array of doubles into a database table as blobs. However when I read them back in, I see they are truncated to 8-bit integers.

Best Answer

The blob datatype is treated as binary strings (byte strings). The JDBC interface defines methods for blobs that operate on byte arrays. As the Database Toolbox uses JDBC or JDBC-ODBC bridge, the data passed from the MATLAB end is converted to a JAVA byte array. In the case of a array of doubles, it is truncated while being converted to an array of bytes. Thus the fetch command returns uint8.
As a workaround, convert the double values to their byte representation using the TYPECAST function. For example if "x" is a array of doubles, the following command:
y=typecast(x,'int8');
will convert it to a array of int8. Now "y" can be inserted into the blob column.
A post processing step will be needed after fetching the data. For example to convert "y" into a array of double, the command is:
x = typecast(y,'double');
Related Question