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

23 views (last 30 days)
erfan nori on 14 Jan 2021
Commented: erfan nori on 15 Jan 2021
Hi
Please help me how to make a 5x5 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
James Tursa on 15 Jan 2021
It sounds as though you have some data that you would like converted, and you have come up with a scheme for converting it but need help with one part of that scheme. Instead of this approach, why don't you tell us what the original data is (size and class), and what you want for a result. Dealing with these intermediate strings you may have created might not be the best overall approach.

Mohammad Sami on 15 Jan 2021
Edited: Mohammad Sami on 15 Jan 2021
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)
##### 2 CommentsShowHide 1 older comment
erfan nori on 15 Jan 2021
Thankful
I used it