how to define binary matrix in matlab?

1 回表示 (過去 30 日間)
Abdelmalek Benaimeur
Abdelmalek Benaimeur 2019 年 4 月 25 日
let's suppose that i have this matrix
A=[0001
0010;
0011;
0100;
0101]
how can i define it to matlab so that it will be reconized as binary matrix and not double ?

採用された回答

James Tursa
James Tursa 2019 年 4 月 25 日
編集済み: James Tursa 2019 年 4 月 25 日
If you mean that you type in the A matrix exactly as above, but want to reinterpret the decimal digits as binary digits, then maybe something like this:
>> A=[0001
0010;
0011;
0100;
0101]
A =
1
10
11
100
101
>> bin = reshape(sprintf('%04d',A),4,[])'
bin =
0001
0010
0011
0100
0101
If you wanted that as a logical matrix instead of a char matrix, then
bin = (bin == '1')
  7 件のコメント
James Tursa
James Tursa 2019 年 4 月 25 日
If you know the size of the original A is 6x3, then simply reshape
>> reshape(bin2dec(num2str(bin)),6,3)
ans =
6 2 2
3 5 1
7 4 6
5 8 3
6 8 9
3 7 9
If you don't know the size of the original A, then you are stuck because that information is not contained in the variable bin. You would need some other way to know what the variable size should be.
Abdelmalek Benaimeur
Abdelmalek Benaimeur 2019 年 4 月 25 日
believe me you are the best
this is for my graduation projet i will add your name as a reference
wish you all the best

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by