xor function

A = ['010','110','111','011',...];
how calculate XOR as B = xor(010,110) >> B 110 then this result xor with the third sting '111'>>>> 001 then this result xor with fourth string '011' and so on

回答 (2 件)

Walter Roberson
Walter Roberson 2012 年 5 月 5 日

1 投票

To get you started:
char('0' + (A{1} ~= A{2})

6 件のコメント

Aseel H
Aseel H 2012 年 5 月 5 日
I did not understand what your mean of this
char('0' + (A{1} ~= A{2})
I need calculate XOR function to each row in a mtrix as
A = [001 111 101 100;101 000 010 111;001 110 010]
I want calculate XOR to [001 xor 111 xor 101 xor 100]
then calculate XOR to [101 xor 000 xor 010 xor 111]
:
:
e.g the final result B = [001;101;100]
Walter Roberson
Walter Roberson 2012 年 5 月 5 日
Your original question shows '010' and '110' which is are strings. Your comment above shows 010 and 111 which are ten and one-hundred-and-eleven decimal, numbers rather than strings. Please clarify the datatype. If it is strings then the only way to store multiple strings in the same array is by using a cell array, the indexing for which uses {} rather than (). If it is decimal numbers then how do you distinguish 0000 from 000 ?
Aseel H
Aseel H 2012 年 5 月 5 日
this is my mistake
datatype is string
A=['001', '111', '101', '100';'101', '000', '010', '111';'001', '110' ,'010']
Aseel H
Aseel H 2012 年 5 月 6 日
Please, Walter Roberson
help me How I can calculate XOR to each row of a matrix have size(50*50) that have string but i givesmall example A(2*3)
A = ['011' '001' '101'
'000' '110' '010'];
I need the result of it '011' xor '001' xor '101'
'000' xor '110' xor '010'
B = ['111'
'000']
because the function B = xor(x,y) calculate xor between two input alone, i need for more two input
Walter Roberson
Walter Roberson 2012 年 5 月 6 日
A = ['011' '001'] means the same as
A = horzcat('011', '001'); which is the same as
A = '011001';
Is that what you want, or do you wish to use cell arrays, which would have the advantage of being able to use the code I already gave?
Note: my previous posting was Saturday afternoon in my time zone, after which I had to do grocery shopping and similar activities, after which I had my first evening out since New Years Eve. If you require responses more quickly than volunteers can reasonably be expected to be available, then it is recommended that you hire a consulting firm.
Aseel H
Aseel H 2012 年 5 月 6 日
@Walter Roberson I'm sorry if I disturbed you with my questions

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

Andrei Bobrov
Andrei Bobrov 2012 年 5 月 5 日

0 投票

A = {'010','110','111','011'};
A1 = cellfun(@(x)x-'0',A,'un',0);
vertxor = rem(sum(cat(1,A1{:})>0),2);
or:
A =[...
0 1 0
1 1 0
1 1 1]
vertxor = rem(sum(A>0),2)
ADDED after Aseel's comment
use cell array (array A)
A = {'011' '001' '101'
'000' '110' '010'};
A1 = cell2mat(reshape(cellfun(@(x)x - '0',A,'un',0),size(A,1),1,[]));
B = cellstr(reshape(sprintf('%d%d%d',rem(sum(A1>0,3),2)),size(A,1),[]))
ADDED after Walter's comment:
A1 = cell2mat(reshape(cellfun(@(x)x - '0',A,'un',0),size(A,1),1,[]));
B = mat2cell(reshape(sprintf('%d',rem(cumsum(A1~=0,3),2)),2,[]),[1 1],[3 3 3]);

2 件のコメント

Walter Roberson
Walter Roberson 2012 年 5 月 6 日
Andrei, the question requires that the calculation be done step by step, for reasons not stated.
Walter Roberson
Walter Roberson 2012 年 5 月 6 日
Step by step does not allow the cellfun solution at all: the poster (for reasons unknown) requires that the xor of the first two sets of data be fully completed and expressed in character for before the second xor is allowed to be started. Efficiency is not the concern in the question: instead the concern is that it be done step-by-step.
Or at least that's the way *I* interpret the question.

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

カテゴリ

ヘルプ センター および File ExchangeCell Arrays についてさらに検索

質問済み:

2012 年 5 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by