Decimal Matrix to Binary Matrix
이전 댓글 표시
Hello,
I am having difficulties in converting a matrix of decimal numbers to its corresponding binary matrix. Here is the problem.
For example, we have a Matrix A;
A=[9 7 15 ; 4 14 8 ]
The range of values in matrix A is from 1 to 16 inclusive. A is in fact an N by 3 matrix. where N is a user-defined integer value. For each decimal number the corresponding binary output should have 5 bits. That is 5 bits per decimal number.
I want the output to be;
Output=[0 1 0 0 1 0 0 1 1 1 0 1 1 1 1 ; 0 0 1 0 0 0 1 1 1 0 0 1 0 0 0]
I tried using the following codes, but it did not work.
A=[9 7 16 ; 4 14 8 ]
x=dec2bin(A');
x=x'; x=str2num(x(:));
Output=x'
I obtain
Output=[ 0 1 0 0 1 0 0 1 1 1 1 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 1 0 0 0]
Can you please help me out?
Hope to hear from you very soon.
Thank you in advance.
Regards,
Amit
채택된 답변
추가 답변 (1개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!