Storing matrices upon each for loop iteration

조회 수: 6 (최근 30일)
Brandon
Brandon 2014년 4월 24일
댓글: Brandon 2014년 4월 24일
Here is my problematic for loop. Everything works fine within the loop except for the k matrix being created. What I want to do is store a new matrix each time a new iteration is done in the for loop. With the vectors I could just use (i,1) and the next value gets stored in the following rows.
Is there some way of doing something similar to this with a 4x4 matrix?
for i = 1:n_e
Xcm = Xc(Sn(i,1),1);
Xcn = Xc(En(i,1),1);
Ycm = Yc(Sn(i,1),1);
Ycn = Yc(En(i,1),1);
L(i,1) = sqrt((Xcn-Xcm)^2+(Ycn-Ycm)^2);
l(i,1) = (Xcn-Xcm)/L(i,1);
m(i,1) = (Ycn-Ycm)/L(i,1);
AEL(i,1) = A(i,1)*E(i,1)/L(i,1);
k = AEL(i,:)*[l(i,1)^2, l(i,1)*m(i,1), -l(i,1)^2, -l(i,1)*m(i,1); m(i,1)^2]; ...
dof(i,:) = [Gdof(2*Sn(i)-1), Gdof(2*Sn(i)), Gdof(2*En(i)-1), Gdof(2*En(i))];
i = i+1;
end

답변 (1개)

Walter Roberson
Walter Roberson 2014년 4월 24일
  댓글 수: 1
Brandon
Brandon 2014년 4월 24일
Thanks for the basic intro, I'm still having trouble either understanding the concept behind arrays or just not doing it properly. The squiggly brackets {} are new to me and upon using them for k{i} the answer shows up as:
k =
[4x4 double] [4x4 double]
where I should get two 4x4 which seems good, but how can I see what the those 4x4 matrices actually are?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by