For Loop to concatenate Matrix Product

2 次查看(过去 30 天)
Hi,
So the matrix A_All will expand in each loop by adding a 4*4 matrix at the end. The 4*4 matrix is generated from some calculation with i.
Let T_i be the 4*4 matrix in i-th loop,
after the 5-th iteration, A_All = [T_1; T_2; T_3; T_4; T_5]
Now I also want a matrix A_0toAll = [T_1; T_1*T_2; T_1*T_2*T_3; T_1*T_2*T_3*T_4; T_1*T_2*T_3*T_4*T_5] after 5-th iteration.
A_All = [];
% doesn't work: A_0toAll = [1 1 1 1; 1 1 1 1;1 1 1 1; 1 1 1 1];
for i=1:5
A_All = [A_All; [i+2 i+3 i+4 i+5;
i+3 i+4 i+5 i+6;
i+4 i+5 i+6 i+7;
0 0 0 1
]
];
T_i = A_All( 4*(i-1)+1 : 4*i , 1 : 4 );
A_0toAll = ??
% doesn't work: A_0toAll = [(A_0toAll); (A_0toAll)*T_i];
end
I tried with what stated in the comments. The result does include all the matrix products I wanted, but it expotentailly produces many other unwanted matrix. I did go with it for further calculation but it exceeds maximum array size preference. So I have to make it neat!
Now I am back to this step and feel quite frustrated......
Please help!

采纳的回答

Bruno Luong
Bruno Luong 2018-12-2
A_All = [];
A_0toAll = [];
C_i = 1;
for i=1:5
T_i = [i+2 i+3 i+4 i+5;
i+3 i+4 i+5 i+6;
i+4 i+5 i+6 i+7;
0 0 0 1];
A_All = [A_All; T_i];
C_i = C_i*T_i;
A_0toAll = [A_0toAll; C_i];
end

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by