Binary matrix, negative number display.

4 ビュー (過去 30 日間)
level1
level1 2021 年 12 月 5 日
回答済み: Image Analyst 2021 年 12 月 8 日
I want to express the subtraction of a binary matrix as a negative number.
ex) = 00000000 - 00001001 = 10001001
Below is the code that I tried.
num = (0:9)';
num_ver = repmat(num,[1,length(num)]);
num_hor = num_ver';
num_comb = [num_hor(:),num_ver(:)];
A = zeros(size(num_comb,1),8);
for ii = 1:length(num_comb)
str2 = dec2bin(-(num_comb(ii,:)),8);
str2_ = [str2;' '];
A(ii,:) = str2num(str2_(:)');
In the case of addition and multiplication, the desired value was output.(sum,prod)
The output value I want is as follows.
A=
[00000000;
10000001;
10000010;
10000011;
10000100;
10000101;
10000110;
10000111;
10001000;
10001001;
00000001;
00000000;
10000001;
10000010;
10000011;
10000100;
10000101;
10000110;
10000111;
10001000;
00000010;
00000001;
00000000;
10000001;
10000010;
10000011;
10000100;
10000101;
10000110;
10000111;
00000011;
00000010;
00000001;
00000000;
10000001;
10000010;
10000011;
10000100;
10000101;
10000110;
00000100;
00000011;
00000010;
00000001;
00000000;
10000001;
10000010;
10000011;
10000100;
10000101;
00000101;
00000100;
00000011;
00000010;
00000001;
00000000;
10000001;
10000010;
10000011;
10000100;
00000110;
00000101;
00000100;
00000011;
00000010;
00000001;
00000000;
10000001;
10000010;
10000011;
00000111;
00000110;
00000101;
00000100;
00000011;
00000010;
00000001;
00000000;
10000001;
10000010;
00001000;
00000111;
00000110;
00000101;
00000100;
00000011;
00000010;
00000001;
00000000;
10000001;
00001001;
00001000;
00000111;
00000110;
00000101;
00000100;
00000011;
00000010;
00000001;
00000000;
];

採用された回答

Image Analyst
Image Analyst 2021 年 12 月 8 日
You'll have to have A be character array or a string array, not a numerical array.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by