For Loop to concatenate Matrix Product
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Laurel Castillo
am 2 Dez. 2018
Beantwortet: Bruno Luong
am 2 Dez. 2018
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!
0 Kommentare
Akzeptierte Antwort
Bruno Luong
am 2 Dez. 2018
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!