how to divide a binary cell into uneven size

6 views (last 30 days)
Jyothi Alugolu
Jyothi Alugolu on 15 Feb 2017
Edited: Jan on 17 Feb 2017
.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 Comment
Jan
Jan on 15 Feb 2017
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}?

Sign in to comment.

Answers (1)

Jan
Jan on 15 Feb 2017
Edited: Jan on 17 Feb 2017
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 Comments
Jan
Jan on 17 Feb 2017
@Jyothi: See the updated code in my answer:
BinCell2Dec({1,1,1,0,0,0,1,1, 1,0,1,0})
% >> [227, 10]

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!