How do I convert data format int16 to real?
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Walter Roberson
el 15 de Sept. de 2016
The value 23368224 that you show requires 24 bits to store, and so cannot be an int16 value.
per isakson
el 15 de Sept. de 2016
Editada: per isakson
el 15 de Sept. de 2016
"23368224"   copy&paste mistake?
Respuestas (2)
Walter Roberson
el 15 de Sept. de 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 comentarios
Steven Lord
el 15 de Sept. de 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
el 15 de Sept. de 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
el 17 de Sept. de 2016
2 comentarios
per isakson
el 17 de Sept. de 2016
Editada: per isakson
el 17 de Sept. de 2016
HDFView opens large files. I use it with HDF5-files of several GB.
 
There are other NetCDF viewers.
Ver también
Categorías
Más información sobre NetCDF en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!