How do I convert data format int16 to real?
11 次查看(过去 30 天)
显示 更早的评论
Dears, I have an array format int16 like this:
A = [14624 11824 12336 23368224 12320 12334 8240 8201 14131]
Could you help me? Thanks so much Oanh
3 个评论
Walter Roberson
2016-9-15
The value 23368224 that you show requires 24 bits to store, and so cannot be an int16 value.
回答(2 个)
Walter Roberson
2016-9-15
I am going to speculate that you want
A = [14624 11824 12336 2336 8224 12320 12334 8240 8201 14131];
and then:
>> typecast(uint16(A),'single')
ans =
4.00685e-11 1.928196e-33 5.825331e-10 1.492372e-19 1.067669e-05
>> typecast(swapbytes(uint16(A)),'single')
ans =
6.334662e-10 1.16203e-19 1.491841e-19 5.82733e-10 4.261631e-08
>> typecast(swapbytes(typecast(uint16(A),'uint32')),'single')
ans =
1.568605e-19 6.407395e-10 1.356318e-19 4.006051e-11 1.928338e-33
None of those looks more obviously right than the others. (The possibilities involving double instead of single look even less plausible.)
2 个评论
Steven Lord
2016-9-15
Using typecast is one option. If the poster wants to change the type of the variable without changing the numeric values stored in the variable, converting it using the double, single, or cast functions as Alexander suggested in his comment is the right approach.
Walter Roberson
2016-9-15
When I see 8 or 16 bit integers to be converted to "real", the context typically turns out to be that single precision numbers have been transmitted over a channel as bytes or words, and those bytes or words need to be rebuilt into single precision values. The swapbytes() I show have to do with the fact that it is common for the byte order for data transmitted from instruments or devices to be different than the native byte order of the MATLAB implementation.
Oanh Bui
2016-9-17
2 个评论
per isakson
2016-9-17
编辑:per isakson
2016-9-17
HDFView opens large files. I use it with HDF5-files of several GB.
 
There are other NetCDF viewers.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NetCDF 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!