필터 지우기
필터 지우기

how to divide a binary cell into uneven size

조회 수: 2 (최근 30일)
Jyothi Alugolu
Jyothi Alugolu 2017년 2월 15일
편집: Jan 2017년 2월 17일
.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
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
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
Jyothi Alugolu
Jyothi Alugolu 2017년 2월 16일
According to the e.g. {1,1,1,0,0,0,1,1, 1,0,1,0}?u hve given..i want the output as 227,10...
Jan
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 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