-1

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.

Rida
  • 21
  • 1
  • 6
  • Please provide a [mcve] with sample inputs and desired output. – beaker Jul 30 '17 at 18:31
  • Plz now check @beaker – Rida Jul 30 '17 at 18:40
  • 1
    Please include sample code showing how to construct your input. I can interpret this is several different ways, each of which would lead to a different solution. Your use of `setxor` is also confusing as this is clearly not a set. – beaker Jul 30 '17 at 18:44
  • bbasically i used c = cellfun(@(x,y) setxor(x,y),b,b,'UniformOutput',false) @beaker BUT its not what i wanted, because it is for two different cell values. I also tried like XOR=setxor(b(1,1),b(1:16)) but i am not getting output i wanted , Infact i am new to matlab and I am really very confused . – Rida Jul 30 '17 at 18:45
  • 1
    This doesn't tell me the structure of the input, which is what I asked for and one of the things that is causing confusion. – beaker Jul 30 '17 at 18:56
  • ok Mr @beaker , you can now see my question, that i interpreted in detail. Plz if u know something like that . – Rida Jul 30 '17 at 18:58
  • 1
    Nope, that doesn't help me at all. Please provide code that I can cut and paste into MATLAB that will produce a cell array like the one you are using for input. Then provide the code that you are trying to use on that code. Finally, provide the output that you want to get from that code with the provided input. – beaker Jul 30 '17 at 19:03
  • That's why you should put updates and clarifications in the question body rather than in comments, you've got more room and more formatting options. Based on what I've seen so far, it would be far easier to take the xor of the integer values in the original array and then convert the result to whatever you want. – beaker Jul 30 '17 at 19:17
  • so how would I apply xor to int array . ? – Rida Jul 30 '17 at 19:19
  • `bitxor(A, A(1,1))` – beaker Jul 30 '17 at 19:19
  • if I use bitxor(163, 163) thats fine but I want to pass full array against 163 . how would it be ? – Rida Jul 30 '17 at 19:20

1 Answers1

1

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'
gnovice
  • 125,304
  • 15
  • 256
  • 359
  • no , i converted it from hexa to dec, then dec2bin, now i have to apply xor gate on binary form as well and my cell is of 16x16 as well , so i want something that setxor(first val of my cell array , all vals of my cell array) – Rida Jul 30 '17 at 18:54
  • 1
    @Rida: You need to do a *much* better job of describing the input data you are starting with in your question. Give us some sample code to generate the input you are using, because it is not clear from your explanation. – gnovice Jul 30 '17 at 18:57
  • @Rida: That still doesn't help. Please provide what I and beaker asked for. It's still not even clear if you are using character arrays (like `a = ['10100011' '11000111' ...]`) or cell arrays (like `a = {'10100011' '11000111' ...};`). – gnovice Jul 30 '17 at 19:09
  • thanks alot,it worked . May u find success , peace n love where u least expect :) – Rida Jul 30 '17 at 19:29