MATLAB: Split string of hex shorts into cell values

split string number curve representation

I have a field from an ODBC connection where the data of a curve is stored in the following way:
  • range for single value is signed 16bit (-32768 to 32767)
  • representation in HEX 4 "digits" with padding left zeros (8000 to 7FFF)
  • all values are concatenated to a string in the database
  • no delimiters
  • number of elements is string length/4
Example:
  • Values (123, 456, -17000)
  • String contains: "007B01C8BD98"
Now I would like to us this data inside Matlab.
I could prepare the data and create a translation database. But I would prefere a direct approach.
All string splitting operators make use of delimiters. But this does not work here.
What is the Matlab/Database Explorer way to get access to that data ? Are there any ready to use functions ?

Best Answer

Simply reshape the string into 4 columns, pass it through dec2hex and account for the fact that dec2hex assumes unsigned integer by casting from unsigned to signed:
s = '007B01C8BD98'; %demo data
typecast(uint16(hex2dec(reshape(s, 4, [])')), 'int16')