Save a series of matrices created using a for loop

조회 수: 1 (최근 30일)
Edith Valle
Edith Valle 2015년 10월 17일
답변: Walter Roberson 2015년 10월 17일
L33=-r2*sin(theta2);
L34=r2*cos(theta2);
L63=rq3*sin(theta3);
L64=rq3*cos(theta3);
L66=(r3-rq3)*sin(theta3);
L67=(r3-rq3)*cos(theta3);
L= [1 0 1 0 0 0 0 0;
0 1 0 1 0 0 0 0;
0 0 0 0 1 0 0 0;
0 0 -1 0 0 1 0 0;
0 0 0 -1 0 0 1 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 -1 0 0;
0 0 0 0 0 0 1 -1]
for i=1:length(t);
%For loop will go through every single value of t and will input every value of L33, L34,L63,L64,L66 and L67 to L matrix
L(3,3)=L33(i)
L(3,4)=L34(i)
L(6,3)=L63(i)
L(6,4)=L64(i)
L(6,6)=L66(i)
L(6,7)=L67(i)
end
So that's the part of my code that I need to fix. The theta values in L33, L34, L63, L64, L66, and L67 depend of t, which is the vector: t=[0:0.1:60]. I got the code to output all the different values of the matrix L with respect to the values of t. However, everytime the loop runs, L is overran and I don't know how to save all the matrices.

채택된 답변

Walter Roberson
Walter Roberson 2015년 10월 17일
for i=1:length(t);
%For loop will go through every single value of t and will input every value of L33, L34,L63,L64,L66 and L67 to L matrix
Lout(:,:,i) = L;
Lout(3,3,i) = L33(i);
Lout(3,4,i) = L34(i);
Lout(6,3,i) = L63(i);
Lout(6,4,i) = L64(i);
Lout(6,6,i) = L66(i);
Lout(6,7,i) = L67(i);
end
Now Lout will be an 8 x 8 x length(t) matrix with the third dimension reflecting changes in t.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by