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
Best Answer