construct a combination matrix from elements of two matrices
조회 수: 6 (최근 30일)
이전 댓글 표시
Hi all,
I have two
matricesAand B, as shown below. Each element is then extended into two which doubles each row, i.e., this gives
extended matrices. What I need to get is the combination between all of these extended elements (for each original row) as shown on the right of the figure where, for example,
means the multiplication of all these elements. As a result, each combination matrix should be
containing all possible combinations, but I am struggling to know how to get it.





Any help would be appreicted.
Thanks.
댓글 수: 1
David Goodmanson
2024년 12월 3일
Hi LH, looking at the 'all possible combinations' in the upper right box above, and ignoring the subscripts which are always 1, and ignoring the primed a's and b's for the moment, you have three combinations:
a1b1, a1b2, a2b1, where these are superscripts. Is there a reason not to have a2b2 ?
답변 (1개)
Sahas
2024년 12월 17일
Hi,
I can't identify any pattern or rule to systematically generate the resulting two matrices using a "for" loop. Therefore, I've provided the following hardcoded implementation. You can edit and replace the positions of the elements if needed.
A = [a1, b1; a2, b2];
B = [a1_hat, b1_hat; a2_hat, b2_hat];
A_ext = [A(1,1), A(1,2); A(1,1), A(1,2); A(2,1), A(2,2); A(2,1), A(2,2)];
B_ext = [B(1,1), B(1,2); B(1,1), B(1,2); B(2,1), B(2,2); B(2,1), B(2,2)];
C1 = [
A_ext(1,1)*B_ext(1,1)*A_ext(1,1)*B_ext(1,1), A_ext(1,1)*B_ext(2,1)*A_ext(1,1)*B_ext(1,1), A_ext(2,1)*B_ext(1,1)*A_ext(1,1)*B_ext(1,1);
A_ext(1,1)*B_ext(1,1)*A_ext(1,1)*B_ext(2,2), A_ext(1,1)*B_ext(2,1)*A_ext(1,1)*B_ext(2,2), A_ext(2,1)*B_ext(1,1)*A_ext(1,1)*B_ext(2,2);
A_ext(1,1)*B_ext(1,1)*A_ext(2,1)*B_ext(1,1), A_ext(1,1)*B_ext(2,1)*A_ext(2,1)*B_ext(1,1), A_ext(2,1)*B_ext(1,1)*A_ext(2,1)*B_ext(1,1)
];
C2 = [
A_ext(3,1)*B_ext(3,1)*A_ext(1,1)*B_ext(1,1), A_ext(3,1)*B_ext(4,1)*A_ext(1,1)*B_ext(1,1), A_ext(4,1)*B_ext(3,1)*A_ext(1,1)*B_ext(1,1);
A_ext(3,1)*B_ext(3,1)*A_ext(1,1)*B_ext(2,2), A_ext(3,1)*B_ext(4,1)*A_ext(1,1)*B_ext(2,2), A_ext(4,1)*B_ext(3,1)*A_ext(1,1)*B_ext(2,2);
A_ext(3,1)*B_ext(3,1)*A_ext(2,1)*B_ext(1,1), A_ext(3,1)*B_ext(4,1)*A_ext(2,1)*B_ext(1,1), A_ext(4,1)*B_ext(3,1)*A_ext(2,1)*B_ext(1,1)
];
I hope this is beneficial!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!