필터 지우기
필터 지우기

For Loop to concatenate Matrix Product

조회 수: 3 (최근 30일)
Laurel Castillo
Laurel Castillo 2018년 12월 2일
답변: Bruno Luong 2018년 12월 2일
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