MATLAB:将uint32(4字节)值转换为相应的IEEE单精度浮点形式

Ole*_*uus 4 floating-point binary matlab double-precision ieee-754

在MATLAB(r2009b)中,我有一个包含值2147484101的uint32变量.

这个数字(4字节)是在抓取过程中从数字机器视觉相机中提取的.根据我的理解,它具有相机快门速度的单精度形式(应接近1/260s = 3.8ms).

如何使用MATLAB中提供的内容将此32位数转换为IEEE单精度浮点表示?

对于变量n中提到的值,我尝试使用nn = dec2hex(n,16)hex2num(nn)的组合.但似乎hex2num期望十六进制编码是双精度的而不是单一的,因为它在这里.至少我用这种方法得到了奇怪的数字.

有任何想法吗?

编辑:尝试@Matt的答案如下:

typecast(uint32(2147484101),'single') %# without swapbytes
typecast(swapbytes(uint32(2147484101)),'single') %# with swapbytes
Run Code Online (Sandbox Code Playgroud)

这使:

ans =

  -6.3478820e-043

ans =

  -2.0640313e+003
Run Code Online (Sandbox Code Playgroud)

我在http://www.h-schmidt.net/FloatApplet/IEEE754.html上尝试了IEEE 754转换器(JAVA applet).

使用:

format hex
typecast(uint32(2147484101),'uint8') %# without swapbytes
typecast(swapbytes(uint32(2147484101)),'uint8') %# with swapbytes
Run Code Online (Sandbox Code Playgroud)

ans =

   c5   01   00   80

ans =

   80   00   01   c5
Run Code Online (Sandbox Code Playgroud)

将这些字节输入applet(十六进制)给出了与MATLAB相同的数字.

Mat*_*att 8

我想你所说的是底层位表示一个浮点数,但是你已将它存储为uint32.

如果是这种情况,您可以使用typecast()函数将其转换为(即重新解释位)作为单个精度浮点数.

b = typecast(a, 'single')
Run Code Online (Sandbox Code Playgroud)

其中a是你的变量.

请参阅:http: //www.mathworks.com/help/techdoc/ref/typecast.html

编辑:不是演员功能,类型转换功能......我道歉!