Borrar filtros
Borrar filtros

For Loop to concatenate Matrix Product

2 visualizaciones (últimos 30 días)
Laurel Castillo
Laurel Castillo el 2 de Dic. de 2018
Respondida: Bruno Luong el 2 de Dic. de 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!

Respuesta aceptada

Bruno Luong
Bruno Luong el 2 de Dic. de 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

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by