Help converting 1 Byte integer data to Short

1 vue (au cours des 30 derniers jours)
Zachary Kober
Zachary Kober le 21 Fév 2021
Commenté : Zachary Kober le 21 Fév 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

Réponse acceptée

Walter Roberson
Walter Roberson le 21 Fév 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')

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by