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
kritika adhikari 2017 年 3 月 19 日
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); ?
kritika adhikari
kritika adhikari 2017 年 3 月 19 日
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 日

0 投票

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 ExchangeResizing 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