Binary matrix, negative number display.

4 visualizaciones (últimos 30 días)
level1
level1 el 5 de Dic. de 2021
Respondida: Image Analyst el 8 de Dic. de 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;
];

Respuesta aceptada

Image Analyst
Image Analyst el 8 de Dic. de 2021
You'll have to have A be character array or a string array, not a numerical array.

Más respuestas (0)

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by