How to compare pair of rows in a column and report it in hexadecimal format

조회 수: 1 (최근 30일)
Hello,
I have a 512x1 matrix (512 rows and 1 column)
The value of ROW1 should be compared with ROW2, similarly ROW3 with ROW4, etc. I have to compute this 256-bit response and report it in hexadecimal format assuming; if ROW1 > ROW2 then 1 & if ROW2 > ROW1 then 0
In this way I will get 256x1 from this.
Please advise!

채택된 답변

Mohammad Sami
Mohammad Sami 2020년 2월 27일
data = rand(512,1);
oddrows = data(1:2:end);
evenrows = data(2:2:end);
response1 = oddrows > evenrows;
response2 = evenrows > oddrows;
response1 = char(response1' + '0');
response2 = char(response2' + '0');
% download bin2hex function from matlab file exchange
% https://www.mathworks.com/matlabcentral/fileexchange/1975-bin2hex
response1hex = bin2hex(response1);
response2hex = bin2hex(response2);
  댓글 수: 6
Mohammad Sami
Mohammad Sami 2020년 2월 27일
response1 = oddrows > evenrows
this would give u the 256 x 1 logical vector
value would be 1 where oddrow is greater then even row and 0 otherwise.
Mohammad Sami
Mohammad Sami 2020년 2월 27일
If you want the values you can do the additional step
response1 = oddrows > evenrows;
values = zero(length(response1),1);
values(response1) = oddrows(response1);
values(~response1) = evenrows(~response1);

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by