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