How to loop in a matrix to obtain the below equations ?
1 回表示 (過去 30 日間)
古いコメントを表示
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ó
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 Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!