Help converting 1 Byte integer data to Short

1 visualización (últimos 30 días)
Zachary Kober
Zachary Kober el 21 de Feb. de 2021
Comentada: Zachary Kober el 21 de Feb. de 2021
Hi all,
I am trying to create a binary file of a 3D medical imaging CT scan with data stored as shorts. Currently I have an array of size A defined as 380x992x208 uint8 that is storing all of the data. I used:
fid = fopen('../atlas.bin', 'w');
fwrite(fid,A);
fclose(fid);
To write this data to a binary file. However after creating this file I noticed that based on the array size there should be 380 x 992 x 208 = 78,407,680 total voxels.
I need each voxel to be a Short, that's 2 bytes per voxel, so size should be 156,815,360 but the file is 78.4 MB. So it looks like the file is made of 1 Byte integers rather than Shorts. If anyone has any advice on how to properly export or change my array, A, so that I can store the data in my binary fike as shorts that would be much appreciated.
-Thanks

Respuesta aceptada

Walter Roberson
Walter Roberson el 21 de Feb. de 2021
fwrite(fid, A, 'uint16')
That would write each byte of your uint8 and would also write a byte of zeros.
You might need
fwrite(fid, A, 'uint16', 'ieee-be')

Más respuestas (0)

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!

Translated by