Byte Array / Bit Conversions in a Cell
13 ビュー (過去 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!