Binary matrix, negative number display.

4 vues (au cours des 30 derniers jours)
level1
level1 le 5 Déc 2021
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;
];

Réponse acceptée

Image Analyst
Image Analyst le 8 Déc 2021
You'll have to have A be character array or a string array, not a numerical array.

Plus de réponses (0)

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Tags

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by