Global Indexing in For loops

3 Ansichten (letzte 30 Tage)
Marcelo Boldt
Marcelo Boldt am 12 Okt. 2020
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

Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by