Save a series of matrices created using a for loop

1 次查看(过去 30 天)
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