Save a series of matrices created using a for loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Edith Valle
am 17 Okt. 2015
Beantwortet: Walter Roberson
am 17 Okt. 2015
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.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 17 Okt. 2015
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!