Azzera filtri
Azzera filtri

How do I convert data format int16 to real?

11 visualizzazioni (ultimi 30 giorni)
Oanh Bui
Oanh Bui il 15 Set 2016
Commentato: Oanh Bui il 26 Set 2016
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 Commenti
Walter Roberson
Walter Roberson il 15 Set 2016
The value 23368224 that you show requires 24 bits to store, and so cannot be an int16 value.
per isakson
per isakson il 15 Set 2016
Modificato: per isakson il 15 Set 2016
"23368224" &nbsp copy&paste mistake?

Accedi per commentare.

Risposte (2)

Walter Roberson
Walter Roberson il 15 Set 2016
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 Commenti
Steven Lord
Steven Lord il 15 Set 2016
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
Walter Roberson il 15 Set 2016
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.

Accedi per commentare.


Oanh Bui
Oanh Bui il 17 Set 2016
Thanks for your answers. Actually, that is windspeed data from ERA-Interim, which the original data format in netCDF format. I'm not familiar with this format. I used MATLAB to read and it was okay. But data values, I can not make sure it is correct or not? With small size netCDF format files (less than 50MB) I could use netCDF Add-ins in Microsoft Excel to read. But a large file size, I can not open it. I compared these data between Matlab reading and from excel, it was not suitable. So, I'm not sure which formatted data I should change from int16? I'm so sorry if my question was not clear above. Thanks.
  2 Commenti
per isakson
per isakson il 17 Set 2016
Modificato: per isakson il 17 Set 2016
HDFView opens large files. I use it with HDF5-files of several GB.
&nbsp
There are other NetCDF viewers.
Did you try to use the Matlab functions to read the NetCDF-file directly?
Oanh Bui
Oanh Bui il 26 Set 2016
Thanks so much, I'm not good at using Matlab code, so the software which was suggested, it will be better for me. Thanks so much once again.

Accedi per commentare.

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by