MATLAB: Change the binary number of a specific group of matrix elements by switching from zero to one and vice versa

binary number of a specific group of matrix elementschange the binary numberMATLABswitching from zero to one

Hi
Please help me how to make a 5×5 matrix whose members are all binary numbers,
For example, select the matrix even elements and then if the binary number is 1111000, convert it to 00001111, in other words, convert one to zero and convert zero to one.
r = 4×4
11001100 11011100 10000010 10010110
10100000 11011000 11010100 10011100
11011001 11001101 10001001 11001011
10001001 11111101 10011100 11111001
convert to
r = 4×4
11001100 00100011 10000010 01101001
10100000 00100111 11010100 01100011
11011001 00110010 10001001 00110100
10001001 00000010 10011100 00000110

Best Answer

If your data is int / uint, you can use the function bitcmp to get the bitwise complement.
a = uint8(1);
b = bitcmp(a);
dec2bin(a,8)
dec2bin(b,8)