Element subtraction of same matrix

1 vue (au cours des 30 derniers jours)
Riaz Anjum
Riaz Anjum le 2 Mar 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.

Réponses (2)

KSSV
KSSV le 2 Mar 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 le 2 Mar 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

Catégories

En savoir plus sur Birthdays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by