how to apply setxor single value of cell array with whole cell array values?

My cell array is binary, 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, Like 10100011 xor 10100011, (first value with first value) 10100011 xor 11000111 , (first val with second value) 10100011 xor 00010111 , (first val with third value) 10100011 xor 11100011 (first val with forth value) but i don't know how to pass full cell array against single value, i tried to use cellfun but that's not working. Your help would be highly appriciiated.

2 Comments

Note: The shown code does not create a "cell array" due to the square brackets instead of curly braces. And if the data is "binary" is a question of the definition, because actually these are vectors of type char. Using logical vectors would allow to apply the xor operation directly.
May be the lengths of each line of a are variable, or Rabia expects them to be variable despite no showing it in the question.

Sign in to comment.

Answers (2)

a = {'10100011' '11000111' '00010111' '11100011'};
result = cellstr( char( mod( cumsum( char( a(:) ) - '0', 1), 2 ) + '0' ) );
(untested)
If you do not want first xor second xor third and so on, then
t = char( a(:) ) - '0';
result = cellstr( char( mod( t(2:end, :) - repmat(t(1,:), size(t,1)-1, 1), 2 ) + '0' ) );
Hi Rabia
a=['10100011'; '11000111'; '00010111'; '11100011'];
L1=a(1,:)';
[s1 s2]=size(a)
s1 =
4
s2 =
8
do you mean this?
xor(repmat(L1',s1,1),a)
=
4×8 logical array
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0

Categories

Asked:

on 30 Jul 2017

Commented:

on 31 Jul 2017

Community Treasure Hunt

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

Start Hunting!