How to loop in a matrix to obtain the below equations ?

조회 수: 2 (최근 30일)
ikram ros salamat
ikram ros salamat 2021년 1월 29일
댓글: Irene Simó 2021년 1월 29일
I have a 3 matrix NxN, Kglobal, C and Mglobal that are the composition of matrixes of the form 6x6 . These 6x6 matrixes one next to another are for the positions x y z . I want to able to study these matrixes each one apart and find the value of H for each matrix. What I tried to do is try to fixate the first six rows (j) while the columns (i) have to take only the 6 matrices dimension, one after the other And for each run I want to save the value of the diagnoal of the matrix. This code gives me that the matrix should be the same dimension and I don't know where is the error?
thanks
for j=1:6:N
for i=1:6:N
H=inv(Kglobal(i:i+5,i:i+5)+1i.*w.*C(i:i+5,i:i+5)-w^2.*Mglobal(i:i+5,i:i+5));
H11(i)=H(1,1);
H22(i)=H(2,2);
H33(i)=H(3,3);
H44(i)=H(4,4);
H55(i)=H(5,5);
H66(i)=H(6,6);
i= i+5;
end
j = j+5;
end
  댓글 수: 1
Irene Simó
Irene Simó 2021년 1월 29일
Hi!
Firslt, I think you forgot to make "j" involved in all of it; it does the loop but there's nothing that is dependant on j on what you wrote.
Secondly, you don't need to add the "i=i+5" and "j=j+5" at the end of the loops, that operation is what the 6 between both : does in the first line of the loops. For the first one, for example, you are creating a loop for which J starts with value 1, and it automatically adds 6 to its value each time it goes thourgh the loop. It stops whenever j reaches the value of N.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by