Help converting 1 Byte integer data to Short

1 view (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 21 Feb 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')

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!