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
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!