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

2 Ansichten (letzte 30 Tage)
ikram ros salamat
ikram ros salamat am 29 Jan. 2021
Kommentiert: Irene Simó am 29 Jan. 2021
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 Kommentar
Irene Simó
Irene Simó am 29 Jan. 2021
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices 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!

Translated by