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

This is 8 by 4 matrix.
per isakson
per isakson 2017년 3월 19일
편집: per isakson 2017년 3월 19일
  • 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.

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

답변 (1개)

Image Analyst
Image Analyst 2017년 3월 19일
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'

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

2017년 3월 19일

댓글:

2017년 3월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by