Help converting 1 Byte integer data to Short

1 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2021-2-21
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')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by