MATLAB: How can i decode an array following some conditions

majority decoding

For ex: We have an array only includes 1s and 0s y= [0 1 0 0 1 1 0 0 1] and a constant value L=3. L is number of times the information bit is repeated previously. How can i reduce this array according to majority? In this ex, we need to reduce it as: [0 1 0] but this reducing should be according to the majority of bites. For example first 3 bits of y are [0 1 0], 0 has the majority so we put a 0 for this. Second part of y is [0 1 1], 1 has the majority, we put 1. Third part is [0 0 1], 0s has majority we put 0. Therfore outcome is [0 1 0].

Best Answer

method one: median:
>> y = [0,1,0,0,1,1,0,0,1];
>> median(reshape(y,3,[]))
ans =
0 1 0
method two: round:
>> round(mean(reshape(y,3,[])))
ans =
0 1 0