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!