Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Rabia Nazli
Rabia Nazli le 30 Juil 2017
Commenté : John BG le 31 Juil 2017
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 commentaires
Jan
Jan le 31 Juil 2017
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.
John BG
John BG le 31 Juil 2017
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.

Connectez-vous pour commenter.

Réponses (2)

Walter Roberson
Walter Roberson le 30 Juil 2017
Modifié(e) : Walter Roberson le 30 Juil 2017
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' ) );

John BG
John BG le 30 Juil 2017
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

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by