HexMat = ['1','2','0';'A','C','8';'9','6','F'];
[m,n] = size(HexMat);
BinaryMat = zeros(m,n*4);
x = zeros(m,n);
for w = 1:m
for v = 1:n
if isequal(HexMat(w,v), '0')
BinaryMat(w,v*4-3) = '0';
BinaryMat(w,v*4-2) = '0';
BinaryMat(w,v*4-1) = '0';
BinaryMat(w,v*4) = '0';
x(w,v) = '0';
elseif isequal(HexMat(w,v), '1')
BinaryMat(w,v*4-3) = '0';
BinaryMat(w,v*4-2) = '0';
BinaryMat(w,v*4-1) = '0';
BinaryMat(w,v*4) = '1';
x(w,v) = '1';
elseif isequal(HexMat(w,v), '2')
BinaryMat(w,v*4-3) = '0';
BinaryMat(w,v*4-2) = '0';
BinaryMat(w,v*4-1) = '1';
BinaryMat(w,v*4) = '0';
x(w,v) = '2';
elseif isequal(HexMat(w,v), '3')
BinaryMat(w,v*4-3) = '0';
BinaryMat(w,v*4-2) = '0';
BinaryMat(w,v*4-1) = '1';
BinaryMat(w,v*4) = '1';
x(w,v) = '3';
elseif isequal(HexMat(w,v), '4')
BinaryMat(w,v*4-3) = '0';
BinaryMat(w,v*4-2) = '1';
BinaryMat(w,v*4-1) = '0';
BinaryMat(w,v*4) = '0';
x(w,v) = '4';
elseif isequal(HexMat(w,v), '5')
BinaryMat(w,v*4-3) = '0';
BinaryMat(w,v*4-2) = '1';
BinaryMat(w,v*4-1) = '0';
BinaryMat(w,v*4) = '1';
x(w,v) = '5';
elseif isequal(HexMat(w,v), '6')
BinaryMat(w,v*4-3) = '0';
BinaryMat(w,v*4-2) = '1';
BinaryMat(w,v*4-1) = '1';
BinaryMat(w,v*4) = '0';
x(w,v) = '6';
elseif isequal(HexMat(w,v), '7')
BinaryMat(w,v*4-3) = '0';
BinaryMat(w,v*4-2) = '1';
BinaryMat(w,v*4-1) = '1';
BinaryMat(w,v*4) = '1';
x(w,v) = '7';
elseif isequal(HexMat(w,v), '8')
BinaryMat(w,v*4-3) = '1';
BinaryMat(w,v*4-2) = '0';
BinaryMat(w,v*4-1) = '0';
BinaryMat(w,v*4) = '0';
x(w,v) = '8';
elseif isequal(HexMat(w,v), '9')
BinaryMat(w,v*4-3) = '1';
BinaryMat(w,v*4-2) = '0';
BinaryMat(w,v*4-1) = '0';
BinaryMat(w,v*4) = '1';
x(w,v) = '9';
elseif isequal(HexMat(w,v), 'A')
BinaryMat(w,v*4-3) = '1';
BinaryMat(w,v*4-2) = '0';
BinaryMat(w,v*4-1) = '1';
BinaryMat(w,v*4) = '0';
x(w,v) = 'A';
elseif isequal(HexMat(w,v), 'B')
BinaryMat(w,v*4-3) = '1';
BinaryMat(w,v*4-2) = '0';
BinaryMat(w,v*4-1) = '1';
BinaryMat(w,v*4) = '1';
x(w,v) = 'B';
elseif isequal(HexMat(w,v), 'C')
BinaryMat(w,v*4-3) = '1';
BinaryMat(w,v*4-2) = '1';
BinaryMat(w,v*4-1) = '0';
BinaryMat(w,v*4) = '0';
x(w,v) = 'C';
elseif isequal(HexMat(w,v), 'D')
BinaryMat(w,v*4-3) = '1';
BinaryMat(w,v*4-2) = '1';
BinaryMat(w,v*4-1) = '0';
BinaryMat(w,v*4) = '1';
x(w,v) = 'D';
elseif isequal(HexMat(w,v), "E")
BinaryMat(w,v*4-3) = '1';
BinaryMat(w,v*4-2) = '1';
BinaryMat(w,v*4-1) = '1';
BinaryMat(w,v*4) = '0';
x(w,v) = 'E';
elseif isequal(HexMat(w,v), 'F')
BinaryMat(w,v*4-3) = '1';
BinaryMat(w,v*4-2) = '1';
BinaryMat(w,v*4-1) = '1';
BinaryMat(w,v*4) = '1';
x(w,v) = 'F';
else
w
v
er = HexMat(w,v)
error('Hexadecimal mismatch error @ coordinates [w,v] of HexMat, defined as variable er')
end
end
end