필터 지우기
필터 지우기

How to do xor operation in cell arrays?

조회 수: 3 (최근 30일)
Darsana P M
Darsana P M 2017년 11월 21일
댓글: Darsana P M 2017년 11월 21일
Suppose,
A={'d9' '31'};
B={'42' '83'};
The expected output is:
Y={'42' '83'}
My input will not be the same always. So,how can I write a useful matlab code for each inputs?
  댓글 수: 6
Darsana P M
Darsana P M 2017년 11월 21일
I am extremely sorry,it was my mistake. The Y result is {'9b' 'b2'}. But using those methods, I am getting a matrix value. Which is the best method for XOR operation, among all those, so that i get the required output.
Darsana P M
Darsana P M 2017년 11월 21일
편집: Walter Roberson 2017년 11월 21일
I tried this method, but I got the output as a matrix. I need the answer as hexa decimal values?? What should I do?

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

채택된 답변

Guillaume
Guillaume 2017년 11월 21일
If you start with a cell array of hexadecimal char arrays and want the same back:
cellfun(@(a,b) dec2hex(bitxor(hex2dec(a), hex2dec(b))), A, B, 'UniformOutput', false)
However, you would make your life easier if instead of a cell array you used a simple 2D char matrix for input and output:
A = ['d9';
'31']
B = ['42';
'83']
Y = dec2hex(bitxor(hex2dec(A), hex2dec(B)))
  댓글 수: 1
Darsana P M
Darsana P M 2017년 11월 21일
Thank you so much sir. This was the answer that I wanted.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 11월 21일
Earlier, I showed you how to do the xor on character vectors. From this you can see how to do the xor operation.
Early this morning, I showed you how to do addition with cell arrays. From this you can see how to extract inputs from cell arrays of character vectors and how to output back to cell arrays.
Now just put those two operations together. Use the data import and output from the addition code and use the xor from the xor code.

카테고리

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