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
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
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!

类别

Help CenterFile Exchange 中查找有关 Simulink Environment Customization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by