Global Indexing in For loops
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!