Element subtraction of same matrix

1 view (last 30 days)
Riaz Anjum
Riaz Anjum on 2 Mar 2021
Answered: Hernia Baby on 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.

Answers (2)

KSSV
KSSV on 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 on 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

Categories

Find more on Birthdays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!