Convert 4char to one double values
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Walter Roberson
el 19 de En. de 2012
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Type Conversion 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!