필터 지우기
필터 지우기

xoring bits within a vector

조회 수: 15 (최근 30일)
emad
emad 2014년 10월 14일
편집: emad 2014년 10월 14일
hi every one.... i'm having a binary matrix with [101101110011 ; 100110110101 ; 011110011001 ; 111100010010] and i want to XOR bit1 with bit3 , bit4 with bit6, bit 7 with bit9, bit 10 with bit 12 for the whole matrix, i try to loop it but it didn't work... help needed
  댓글 수: 1
Guillaume
Guillaume 2014년 10월 14일
Is your matrix an n x 12 char array, a cell array of strings, or something else.
Assuming your matrix is called m, can you show the output of
whos m

댓글을 달려면 로그인하십시오.

채택된 답변

Thorsten
Thorsten 2014년 10월 14일
Use space between the the 1's and 0's
M = [1 0 1 1 0 1 1 1 0 0 1 1 ; 1 0 0 1 1 0 1 1 0 1 0 1 ; 0 1 1 1 1 0 0 1 1 0 0 1 ; 1 1 1 1 0 0 0 1 0 0 1 0];
xor(M(:, 1:3:end), M(:, 3:3:end))
  댓글 수: 1
emad
emad 2014년 10월 14일
편집: emad 2014년 10월 14일
thanks Thorsten you save my day one more thing, what if i want to xor every three bits together?

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Guillaume
Guillaume 2014년 10월 14일
Assuming your matrix is an n x 12 char array, and assuming bit 1 is the first bit on the left.
m = ['101101110011' ; '100110110101' ; '011110011001' ; '111100010010'];
mnum = m - '0'; %convert the strings into a matrix of 0/1 integers
mnxor = xor(mnum(:, [1 4 7 10]), mnum(:, [3 6 9 12])); %perform the xor. Change each array for specific bits.
mxor = char(mnxor + '0'); %convert back into a char array

emad
emad 2014년 10월 14일
편집: emad 2014년 10월 14일
dear Guillaume thanks very much your code works very good...

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by