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 CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by