Global Indexing in For loops
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Dear Community!
I have been working on a project where I find myself a little bit stuck:
I have elements, where each of them has 4 3x3 matrices associated. In total I have 215 Elements and therefore, I have a cell array of 430x2 dimension. The next step is to obtain a 215x215 diagonal matrix according to the picture attached. The problem I am currently facing is that I need to perform the following sum :
the sum of the 4th matrix of the (n-1)th element + the 1st matrix of the nth element. I know I need some sort of global index or something to tell the script how to perform the addition but I am not familiar with the syntax. Do you have any answer to that?
Thanks!
for i = 1:2:215
for j = 1:2:215
if (i==1) && (i==j)
Structure_Global_Stiffness{i,i} = Resultant_K{i,1};
Structure_Global_Stiffness{i,i+1} = Resultant_K{i,2};
elseif (i==j) && (i<215)
Structure_Global_Stiffness{i,i-1} = Resultant_K{i,1};
Structure_Global_Stiffness{i,i} = Resultant_K{i,2} + Resultant_K{i+1,1};
Structure_Global_Stiffness{i,i+1} = Resultant_K{i+1,2};
elseif (i==j) && (i==215)
Structure_Global_Stiffness{i,i-1} = Resultant_K{i,1};
Structure_Global_Stiffness{i,i} = Resultant_K{i,2};
elseif (j < i-1)
Structure_Global_Stiffness{i,j} = zeros(3);
elseif (i==1) && (j > i+1)
Structure_Global_Stiffness{i,j} = zeros(3);
elseif (i > 1) && (j > i+1)
Structure_Global_Stiffness{i,j} = zeros(3);
end
end
end
0 Commenti
Risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!