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
kritika adhikari
2017년 3월 19일
per isakson
2017년 3월 19일
편집: per isakson
2017년 3월 19일
- What do you mean by "binary"?
- What about   B=(M>=21); ?
kritika adhikari
2017년 3월 19일
답변 (1개)
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에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!