フィルターのクリア

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

1 回表示 (過去 30 日間)
Rabia Nazli
Rabia Nazli 2017 年 7 月 30 日
コメント済み: John BG 2017 年 7 月 31 日
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 件のコメント
Jan
Jan 2017 年 7 月 31 日
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 2017 年 7 月 31 日
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.

サインインしてコメントする。

回答 (2 件)

Walter Roberson
Walter Roberson 2017 年 7 月 30 日
編集済み: Walter Roberson 2017 年 7 月 30 日
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 2017 年 7 月 30 日
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

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by