8 digit double array to 1 digit double array

조회 수: 4 (최근 30일)
Hye Sung Moon
Hye Sung Moon 2020년 4월 15일
댓글: Walter Roberson 2020년 4월 16일
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.

채택된 답변

Walter Roberson
Walter Roberson 2020년 4월 15일
편집: Walter Roberson 2020년 4월 15일
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
Walter Roberson
Walter Roberson 2020년 4월 16일
And you need the same number of digits in each number. It is a "fast and dirty" answer, not the best answer.
Walter Roberson
Walter Roberson 2020년 4월 16일
cell2mat(compose('%08d',H(:)))-'0'

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Tommy
Tommy 2020년 4월 15일
How about
H_conv = num2str(H)-'0'

James Tursa
James Tursa 2020년 4월 15일
For column vector H:
H_conv = cell2mat(arrayfun(@(x)sprintf('%08d',x),H,'uni',false)) - '0'

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by