how to divide a binary cell into uneven size
1 回表示 (過去 30 日間)
古いコメントを表示
.i have 4 binary(0's and 1's ) cells of sizes 1*1120, 1*1344, 1*868, 1*812... now, i need to split or do partition on each cell i.e the entire cell must divide into each 8 bits,so that output of cell's must be of size 1st cell: 8*140, 2nd cell: 8*168, 3rd cell must be 8*109.. 109 because 108 columns contains 108*8=864 binary numbers,and there will remain 4 binary number's.. these 4 binary numbers must store in another column i.e 109th column.. so 3rd cell size must be 8*109.. and 4th cell size must be 8*102 ... and finally i need to calculate decimal value for each splitted file.. in case of 3rd cell, the 109th column contains 4 elements, these 4 elements also must convert into decimal value... final decimal vector must contain size of 1*140, 1*168, 1*109, 1*102....
1 件のコメント
Jan
2017 年 2 月 15 日
Please post a samll example of the input data. In the case of the 4 remaining bits: are these the most or least significant bits? What is e,g, the wanted output value for {1,0,1,0}?
回答 (1 件)
Jan
2017 年 2 月 15 日
編集済み: Jan
2017 年 2 月 17 日
Working with cells is not efficient here. If possible store elements of equal size and type in a numerical vector. But it works with cells also:
% [EDITED 2017-02-17 07:44 UTC]
C = {0,1,0,1,0,1,1,1,1,0,1,0}; % Example data
D = BinCell2Dec(C)
And the function for the conversion:
function Num = BinCell2Dec(C)
n8 = ceil(length(C) / 8);
D = zeros(8, n8);
D(1:numel(C)) = [C{:}]; % Convert cell to numerical array
nLast = mod(length(C), 8);
if nLast % Shift last block to right:
D(:, n8) = [zeros(8 - nLast, 1); D(1:nLast, n8)];
end
Num = [128,64,32,16,8,4,2,1] * D;
end
6 件のコメント
Jan
2017 年 2 月 17 日
@Jyothi: See the updated code in my answer:
BinCell2Dec({1,1,1,0,0,0,1,1, 1,0,1,0})
% >> [227, 10]
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!