From: Richard Gueler on 15 Jul 2010 21:58 I am reading bunch of binary data from a device that is mixed with various datatypes. The binary data is read in as a "uint8" array. I need to convert this binary data to other various datatypes. For example, elements 40-47 in the array represent a "double". Elements 36-37 are a "uint16". Any suggestions on how I can convert this binary data to the other datatypes?
From: Walter Roberson on 15 Jul 2010 23:04 Richard Gueler wrote: > I am reading bunch of binary data from a device that is mixed with > various datatypes. The binary data is read in as a "uint8" array. I > need to convert this binary data to other various datatypes. For > example, elements 40-47 in the array represent a "double". Elements > 36-37 are a "uint16". Any suggestions on how I can convert this binary > data to the other datatypes? See typecast() However, if you have an external binary file, the representation of "double" or "uint16" might not be the same as in your Matlab; in particular, the byte ordering might be different even if the same IEEE 754 binary arithmetic standard was used.
From: Steven Lord on 15 Jul 2010 23:22 "Walter Roberson" <roberson(a)hushmail.com> wrote in message news:J_P%n.22423$4B7.5584(a)newsfe16.iad... > Richard Gueler wrote: >> I am reading bunch of binary data from a device that is mixed with >> various datatypes. The binary data is read in as a "uint8" array. I >> need to convert this binary data to other various datatypes. For >> example, elements 40-47 in the array represent a "double". Elements >> 36-37 are a "uint16". Any suggestions on how I can convert this binary >> data to the other datatypes? > > See typecast() > > However, if you have an external binary file, the representation of > "double" or "uint16" might not be the same as in your Matlab; in > particular, the byte ordering might be different even if the same IEEE 754 > binary arithmetic standard was used. In which case the OP may need to use SWAPBYTES in conjunction with TYPECAST, or to open the file using FOPEN with a specific endian-ness. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
From: Richard Gueler on 16 Jul 2010 10:25 "Steven Lord" <slord(a)mathworks.com> wrote in message <i1ojah$h1d$1(a)fred.mathworks.com>... > > "Walter Roberson" <roberson(a)hushmail.com> wrote in message > news:J_P%n.22423$4B7.5584(a)newsfe16.iad... > > Richard Gueler wrote: > >> I am reading bunch of binary data from a device that is mixed with > >> various datatypes. The binary data is read in as a "uint8" array. I > >> need to convert this binary data to other various datatypes. For > >> example, elements 40-47 in the array represent a "double". Elements > >> 36-37 are a "uint16". Any suggestions on how I can convert this binary > >> data to the other datatypes? > > > > See typecast() > > > > However, if you have an external binary file, the representation of > > "double" or "uint16" might not be the same as in your Matlab; in > > particular, the byte ordering might be different even if the same IEEE 754 > > binary arithmetic standard was used. > > In which case the OP may need to use SWAPBYTES in conjunction with TYPECAST, > or to open the file using FOPEN with a specific endian-ness. > > -- > Steve Lord > slord(a)mathworks.com > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ > To contact Technical Support use the Contact Us link on > http://www.mathworks.com > It worked! I had to swap the byte ordering. I did the following: new_data = swapbytes(typecast(data(40:47),'double')) Thanks
|
Pages: 1 Prev: Export executable in Linux Next: Simscape power converter model |