Element subtraction of same matrix

1 visualización (últimos 30 días)
Riaz Anjum
Riaz Anjum el 2 de Mzo. de 2021
Respondida: Hernia Baby el 2 de Mzo. de 2021
I have a square matrix, suppose 2x2 matrix.
For example A = [2,5; 3,8]; Its order is 2x2.
I want an answer which is double in order of A.
I need a code for subtraction A-A in such a ways that answer will show the arrangement below.
Answer = [2-2, 2-5, 2-3, 2-8; 5-2, 5-5, 5-3, 5-8; 3-2, 3-5, 3-3, 3-8; 8-2, 8-5, 8-3, 8-8];
The order of "Answer" is double of A matrix.

Respuestas (2)

KSSV
KSSV el 2 de Mzo. de 2021
A = [2,5; 3,8];
B = [2-2, 2-5, 2-3, 2-8; 5-2, 5-5, 5-3, 5-8; 3-2, 3-5, 3-3, 3-8; 8-2, 8-5, 8-3, 8-8];
A1 = A' ;
C = (A1(:)'-A1(:))' ;
isequal(B,C)

Hernia Baby
Hernia Baby el 2 de Mzo. de 2021
A = [2,5; 3,8];
B = [2-2, 2-5, 2-3, 2-8; 5-2, 5-5, 5-3, 5-8; 3-2, 3-5, 3-3, 3-8; 8-2, 8-5, 8-3, 8-8];
A = A';
Answer = repmat(A(:),1,4) - repmat(A(:)',4,1);
Answer == B

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by