Help converting 1 Byte integer data to Short

조회 수: 2 (최근 30일)
Zachary Kober
Zachary Kober 2021년 2월 21일
댓글: Zachary Kober 2021년 2월 21일
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