Byte Array / Bit Conversions in a Cell
조회 수: 12 (최근 30일)
이전 댓글 표시
I'm not too familiar with Matlab, and I'm having a trouble with cell operations. I have 2 questions:
1- ) Think a byte array cell which consist of 1000x4 uint8 type. I want to convert it into a cell which is 1000x1 uint32 type. Byte order of byte array is big endian. I'm having a trouble with implementing the 'typecast' method to this cell without any loop for time efficiency.
2-) Again think the uint8 type cell which is 1000x1. I need to split it to bits. As a result I want to obtain 8 cells 1000x1 for every bit. But again I could not handle with the 'bitget' method for cells.
Thanks a lot!
댓글 수: 0
채택된 답변
Steven Lord
2021년 6월 22일
If all your numeric data is the same type, I recommend storing it in a numeric array rather than as a cell array. Let's make some sample int8 data:
rng default
x = randi([0 intmax('int8')], 3, 4, 'int8')
Now to convert this to int32 we need to first make it a vector. I'm going to convert each row of x into an int32 so:
xvec = reshape(x.', 1, [])
y = typecast(xvec, 'int32').'
Let's look at the hex digit patterns.
format hex
disp(x)
disp(y)
Or perhaps you want the first column of x to have the most significant bits in y, the second column the next most significant, etc.? If so take a look at the swapbytes function.
disp(swapbytes(y))
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!