필터 지우기
필터 지우기

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 CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by