Convert 4char to one double values

1 次查看(过去 30 天)
Hi, I have some data in a byte(char) format that i want to convert to double format. Does anyone tell how to do this in matlab?
I have read the data in to a char, where every 4 characters should represent a double.
My data looks like this :
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
Thanks in advance

采纳的回答

Walter Roberson
Walter Roberson 2012-1-19
There are multiple methods of doing the conversion, depending on the byte order that the numbers were stored in compared to the byte order your machine is using.
Are you certain that you want 4 characters to represent a double, not a single ? If double then is the data representation custom or is the data stored as a single but you want a double as output? That is, double is 64 bits which is 8 bytes and single is 4 bytes.
If your data is a multiple of 4 bytes and each byte was stored to an individual character (the usual), and your byte orders match, and the 4 bytes are in the format of a single, then:
double(typecast(uint8(Data), 'single'))
(But easier would be to read it from the file as numeric.)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by