Matrix mapping in order to get its elements in binary form.

I have a matrix with columns and rows having indices on it. Is it possible to create the matrix from same provided matrix in binary form. For example.1st row 1st column of the matrix in 29. Is it possible by any chance I can get 1 or 0 here.
M = [ 29 22 15 8
37 30 23 16
45 38 31 24
1 46 39 32
5 1 47 40
13 6 1 48
21 14 7 1 ];

3 Comments

  • What do you mean by "binary"?
  • What about &nbsp B=(M&gt=21); ?
Actually I have a matrix with indices on it. Is there any way (mapping) so that I can get my matrix with 1 and 0 on it. It doesnot mean converting 8 to binary form.

Sign in to comment.

Answers (1)

Try this:
m=[...
29 22 15 8
37 30 23 16
45 38 31 24
1 46 39 32
5 1 47 40
13 6 1 48
21 14 7 1]
[rows, columns] = size(m)
for col = 1 : columns
for row = 1 : rows
caM{row, col} = dec2bin(m(row, col));
end
end
caM % Print to command window
The results:
caM =
7×4 cell array
'11101' '10110' '1111' '1000'
'100101' '11110' '10111' '10000'
'101101' '100110' '11111' '11000'
'1' '101110' '100111' '100000'
'101' '1' '101111' '101000'
'1101' '110' '1' '110000'
'10101' '1110' '111' '1'

Categories

Asked:

on 19 Mar 2017

Commented:

on 19 Mar 2017

Community Treasure Hunt

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

Start Hunting!