8 digit double array to 1 digit double array

Hi, I am trying to extract 8 digit double array to 1 digit double array.
H = [10001000;
10000001]
I would like to save H(2*1) double matrix to
H_conv = [ 1 0 0 0 1 0 0 0;
1 0 0 0 0 0 0 1]
H_conv(2*8) double matrix.
Thank you.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 15 de Abr. de 2020
Editada: Walter Roberson el 15 de Abr. de 2020
num2str(H) - '0'
This relies upon H being a column vector and will not give you the desired answer if H has more than one column.
It will also not give your desired answer if the top digit of H is not set in all values.

4 comentarios

Hye Sung Moon
Hye Sung Moon el 16 de Abr. de 2020
Thank you! It works perfectly!
James Tursa
James Tursa el 16 de Abr. de 2020
Editada: James Tursa el 16 de Abr. de 2020
... as long as you have a leading 1 in each number. Do you know this for sure about each value?
Walter Roberson
Walter Roberson el 16 de Abr. de 2020
And you need the same number of digits in each number. It is a "fast and dirty" answer, not the best answer.
cell2mat(compose('%08d',H(:)))-'0'

Iniciar sesión para comentar.

Más respuestas (2)

James Tursa
James Tursa el 15 de Abr. de 2020
For column vector H:
H_conv = cell2mat(arrayfun(@(x)sprintf('%08d',x),H,'uni',false)) - '0'

Categorías

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

Etiquetas

Aún no se han introducido etiquetas.

Preguntada:

el 15 de Abr. de 2020

Comentada:

el 16 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by