Global Indexing in For loops

1 次查看(过去 30 天)
Marcelo Boldt
Marcelo Boldt 2020-10-12
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 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by