My cell array,it contain values like a=['10100011' '11000111' 00010111' 11100011 ']; I want to apply xor operation ; I used setxor. I want to xor first value of array i.e 10100011 to all values of cell arrays,required input & output is as follows !
**setxor(10100011, 10100011) =00000000%(first value xor result with first value)
setxor(10100011 , 11000111) =1100100%(first val xor result with second value)
setxor(10100011, 00010111 )=10110100%(first val xor result with third value)
setxor(10100011 ,11100011)=1000000 %(first val xor result with forth value)**
but i don't know how to pass full cell array and single value, i tried to use cellfun but that's not working. I want something that setxor(first val of my cell array , all vals of my cell array) as my cell array is 16x16. Your help would be highly appriciated.
If you're starting from data that looks like this:
A = [163 215 9 131 248 72 246 244 179 33 21 120 153 177 175 249; ...
231 45 77 138 206 76 202 46 82 149 217 30 78 56 68 40];
And you want to XOR the bits of the first entry with every other entry, you don't have to convert A
using dec2bin
. You can just use bitxor
, then format the result however you want (decimal or cell arrays of binary strings):
>> decOut = bitxor(A(1), A)
decOut =
0 116 170 32 91 235 85 87 16 130 182 219 58 18 12 90
68 142 238 41 109 239 105 141 241 54 122 189 237 155 231 139
>> binOut = reshape(cellstr(dec2bin(decOut)), size(A))
binOut =
2×16 cell array
Columns 1 through 10
'00000000' '01110100' '10101010' '00100000' '01011011' '11101011' '01010101' '01010111' '00010000' '10000010'
'01000100' '10001110' '11101110' '00101001' '01101101' '11101111' '01101001' '10001101' '11110001' '00110110'
Columns 11 through 16
'10110110' '11011011' '00111010' '00010010' '00001100' '01011010'
'01111010' '10111101' '11101101' '10011011' '11100111' '10001011'