Write a function encodedgt that takes as input a column or row vector with integer entries and produces as output a row vector where each integer is encoded according to the following table
Integer Encoding 0 0 0 0 1 1 0 1 1 0 0 1 1 0 0 1 2 0 0 1 0 0 1 1 3 0 1 1 1 1 0 1 ... etc.
and the rule encodedgt(x) = 1 - encodedgt(-(x+1)) when x < 0.
For example,
encodedgt([1 12 -3])
[0 0 1 1 0 0 1 0 1 0 1 0 1 1 0 1 1 0 0]
So I already wrote a script that works fine with positive numbers which is the following...
function x = encodedgt(x)
enc = {0, '0 0 0 1 1 0 1'; 1 , '0 0 1 1 0 0 1'; 2, '0 0 1 0 0 1 1';... 3, '0 1 1 1 1 0 1'; 4, '0 1 0 0 0 1 1'; 5, '0 1 1 0 0 0 1'; 6, ... '0 1 0 1 1 1 1'; 7, '0 1 1 1 0 1 1'; 7, '0 1 1 1 0 1 1'; 8, ... '0 1 1 0 1 1 1'; 9, '0 0 0 1 0 1 1'; 10, '0 0 0 0 1 0 1'; 11, ... '1 0 1 0 0 0 0'; 12, '0 1 0 1 0'};
y = str2num(cell2mat(arrayfun(@(v)enc{find([enc{:, 1}]) == v, 2}', x(:), 'UniformOutput',0)))'
end
HOWEVER, I'm not entirely sure how to get it to work with negative numbers. As the question tells me, encodedgt(x) = 1 - encodedgt(-(x+1)) when x < 0. So I thought about using an if statement but er it's not coming out exactly to plan. Is there a better way to approach this?