how can I groups binary digits in array element

i have the following array with randomly binary number in sequence, but i want to divide into 4 groups of bits such as array B from A
A=[11 1 1 1 1 1 1 1 0 1 0 1 0 1 0]
to be in a form
B=[1111;1111;1010;1010]

 Respuesta aceptada

Ameer Hamza
Ameer Hamza el 19 de Nov. de 2020
Editada: Ameer Hamza el 19 de Nov. de 2020
Try this combination of sprintf and sscanf.
A = [11 1 1 1 1 1 1 1 0 1 0 1 0 1 0];
B = sscanf(sprintf('%d', A), '%4d');
Result
>> B
B =
1111
1111
1010
1010

2 comentarios

dani elias
dani elias el 19 de Nov. de 2020
thank you
Ameer Hamza
Ameer Hamza el 19 de Nov. de 2020
I am glad to be of help!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Centro de ayuda y File Exchange.

Preguntada:

el 19 de Nov. de 2020

Comentada:

el 19 de Nov. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by