how to perform bitwise XOR operation and scramble two matrices
Mostrar comentarios más antiguos
Hello
I need to perform XOR operation for four variables where each of them are represented as follows
A=00
G=01
C=10
T=11
and generate a table which gives the values for all combinations
XOR A G C T
A A G C T
G G A T C
C C T A G
T T C G A
This is the XOR rule im trying to apply on two matrices.... for eg:
A = 'GATT' 'AACT' 'ACAC' 'TTGA' 'GGCT'
'GCAC' 'TCAT' 'GTTC' 'GCCT' 'TTTA'
'AACG' 'GTTA' 'ACGT' 'CGTC' 'TGGA'
'CTAC' 'AAAA' 'GGGC' 'CCCT' 'TCGT'
'GTGT' 'GCGG' 'GTTT' 'TTGC' 'ATTA'
B= 'ATAC' 'AAAT' 'AGCT' 'AAGC' 'AAGT'
'TAGG' 'AAGT' 'ATGA' 'AAAG' 'AAGA'
'TAGC' 'CAGT' 'AGAT' 'GAAG' 'TCGA'
'GCTA' 'TTAC' 'GCCA' 'CCCC' 'TTTC'
'CCAA' 'AGGA' 'GCAG' 'CAGC' 'TAAA'
C= A XOR B
for eg consider the first element...
A XOR B= GATT XOR ATAC= GTTG
i want to do this for the whole matrix.Will it be easy if a function is defined and then called?? pls help..thanks in advance..
Respuesta aceptada
Más respuestas (3)
Image Analyst
el 23 de Ag. de 2014
0 votos
Why'd you tag it with image processing? And can't you use repmat() to extend your row and column vectors into a full matrix then just do xor(a,b)?
1 comentario
Abirami
el 24 de Ag. de 2014
Geoff Hayes
el 23 de Ag. de 2014
Editada: Geoff Hayes
el 23 de Ag. de 2014
Abirami - try the following.
% create the char vector in this order, since A==0, G==1, C==2,
% and T==3, the index for any of these elements will be its binary
% value plus one i.e. G is 01 so its index is 1+1=2
char_array = ['A' ; 'G' ; 'C' ; 'T'];
% pre-allocate memory to the output matrix
char_mtx = cell(4,4);
% now iterate over each pair from the char array
for u=1:4
for v=1:4
% do the bitxor: note how we subtract one since u,v start
% at one
res = bitxor(u-1,v-1);
% copy the character, adding one, to the output matrix
char_mtx{u,v} = char_array(res+1);
end
end
The output is
char_mtx =
'A' 'G' 'C' 'T'
'G' 'A' 'T' 'C'
'C' 'T' 'A' 'G'
'T' 'C' 'G' 'A'
Try the above and see what happens!
aaru sri
el 18 de Nov. de 2018
0 votos
Error using bitxor
Double inputs must have integer values in the range of ASSUMEDTYPE.
%%%%%above is the error coming
fx1=bitxor(fx,j1,)
fx contains the negative values also
how can i solve this or what mistake i m making
1 comentario
Image Analyst
el 18 de Nov. de 2018
This is not an answer for Abirami's question. Please read this link and then post your own answer. Since you will have read that link, your new question will of course include more data (images, code, etc.) that will allow people to solve your mistake, unlike now.
Categorías
Más información sobre Convert Image Type en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!