How to compare pair of rows in a column and report it in hexadecimal format
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Farhan K
el 27 de Feb. de 2020
Comentada: Mohammad Sami
el 27 de Feb. de 2020
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 comentarios
Respuesta aceptada
Mohammad Sami
el 27 de Feb. de 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 comentarios
Mohammad Sami
el 27 de Feb. de 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
el 27 de Feb. de 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);
Más respuestas (0)
Ver también
Categorías
Más información sobre String Parsing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!