How do I convert data format int16 to real?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Walter Roberson
le 15 Sep 2016
The value 23368224 that you show requires 24 bits to store, and so cannot be an int16 value.
per isakson
le 15 Sep 2016
Modifié(e) : per isakson
le 15 Sep 2016
"23368224"   copy&paste mistake?
Réponses (2)
Walter Roberson
le 15 Sep 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 commentaires
Steven Lord
le 15 Sep 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
le 15 Sep 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.
Oanh Bui
le 17 Sep 2016
2 commentaires
per isakson
le 17 Sep 2016
Modifié(e) : per isakson
le 17 Sep 2016
HDFView opens large files. I use it with HDF5-files of several GB.

 
There are other NetCDF viewers.
Voir également
Catégories
En savoir plus sur Large Files and Big Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!