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.
댓글 수: 0
답변 (2개)
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)
댓글 수: 0
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
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!