Storing outputs from loop iterations into a 1 dimensional array
이전 댓글 표시
Hi,
I need help storing iterations from a for loop into a 1 dimensional array in MATLAB. Here's my script:
M=input('Enter matrix M ');
K=input('Enter constant vector K ');
n=input('Enter number of unknown forces n ');
for i=1:n
CramerCalc(M,K,i);
end
And my function:
function [ F ] = CramerCalc( M,K,i )
D=det(M);
Mat=M;
Mat(:,i)=K(:);
C=det(Mat);
F=C/D;
V(i,:)=[F]
What I'm getting: V =
134.1989
V =
0
169.7423
V =
0
0
120.0259
V =
0
0
0
0
V =
0
0
0
0
60.0259
V =
0
0
0
0
0
120.0259
How can I put it all into one?
Also, if you can, could you please teach me how to code the for loop to store each answer under different names? For example, the answer from the first iteration would be stored as F1, the second as F2, so on and so forth.
Finally, how would I be able to combine the 2 previous things so that the array would come out like this: V=[F1 F2 F3 F4 F5 F6]
Thank you in advance for any help!
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!