Element subtraction of same matrix

1 次查看(过去 30 天)
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.

回答(2 个)

KSSV
KSSV 2021-3-2
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 2021-3-2
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

类别

Help CenterFile Exchange 中查找有关 Birthdays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by