For Loop to concatenate Matrix Product
Show older comments
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!
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!