# how to perform bitwise logical xor for two matrices having 13 bit binary data each?

11 Ansichten (letzte 30 Tage)
Abirami am 29 Jan. 2015
Beantwortet: Dr. Suneetha CH am 18 Aug. 2020
I have two cell arrays with each element having 13 bit binary strings. How to perform bitwise XOR for these two cell arrays.
For eg: consider two 3x3 cell arrays A and B
A= '1011111111011' '1011111111011' '1011111111011'
'1100000111111' '1100000111111' '1100000111111'
'1100000001000' '1100000001000' '1100000001000'
B= '1100001001010' '1100001001010' '1100001001010'
'1011111100010' '1011111100010' '1011111100010'
'1100000001110' '1100000001110' '1100000001110'
My desired output is as below
C=A XOR B
ie C(1,1)= '1011111111011' XOR '1100001001010'
C(1,1)= '0111111011001'
Similarly for all the elements a bitwise XOR should be performed
##### 2 KommentareKeine anzeigenKeine ausblenden
Guillaume am 29 Jan. 2015
Your example shows two cell arrays containing strings (made up of characters '0' and '1'), not two matrices containing binary data (which is a just numbers)
So, do you have matrices or cell arrays, and do they contain strings or numbers?
Abirami am 29 Jan. 2015
Ive edited the qn sir....

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Guillaume am 29 Jan. 2015
Bearbeitet: Guillaume am 29 Jan. 2015
Assuming that what you have are cell arrays of strings, and you want to output a cell array of string as well, this would be one way to do it:
A = {'1011111111011' '1011111111011' '1011111111011'
'1100000111111' '1100000111111' '1100000111111'
'1100000001000' '1100000001000' '1100000001000'};
B = {'1100001001010' '1100001001010' '1100001001010'
'1011111100010' '1011111100010' '1011111100010'
'1100000001110' '1100000001110' '1100000001110'};
C = cellfun(@(a,b) char((a ~= b) + '0'), A, B, 'UniformOutput', false)
However, I don't really see a reason to operate on strings, when operating on numbers (and keeping it that way) would be much faster:
A = reshape(bin2dec(A), size(A))
B = reshape(bin2dec(B), size(B))
C = bitxor(A, B)
##### 4 Kommentare2 ältere Kommentare anzeigen2 ältere Kommentare ausblenden
Guillaume am 29 Jan. 2015
Bearbeitet: Guillaume am 29 Jan. 2015
Hum, are you sure you've run the first two lines (i.e. converted your cell arrays of strings into matrices of numbers)? By the 3rd line, A and B shouldn't be cell anymore.
Rabia Nazli am 30 Jul. 2017
setxor can be used, like c=setxor(A,B)

Melden Sie sich an, um zu kommentieren.

### Weitere Antworten (2)

Ramya M S am 1 Feb. 2017
how can i xor 4 bit and 8 bit data?
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Dr. Suneetha CH am 18 Aug. 2020
how to perform bitwise xor successively? i mean a XOR b XOR c .....
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by