How to compare pair of rows in a column and report it in hexadecimal format
1 view (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Mohammad Sami
on 27 Feb 2020
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 Comments
Mohammad Sami
on 27 Feb 2020
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
on 27 Feb 2020
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);
More Answers (0)
See Also
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!