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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by