Cell array variable problem
2 次查看(过去 30 天)
显示 更早的评论
Dear Community,
I am facing a rather basic problem but unfortunately I cannot fix it:
I have a nested loop that gives me as output a 324x324 cell that contains in each variable a associated matrix of 3x3. In addition, the important values are placed in the diagonal of the cell array, while the rest of the variables should be zero matrices of 3x3. the problem is that, I cannot assign the zero matrix to the remaining variables. The code goes as follow:
K_TANK_TOTAL = [K_tank_reinforcement;K_reinforcement;K_spherical_dome];
Structure_Global_Stiffness = cell(324,324);
Matrix_0 = zeros(3,3);
for kk = 1:324
for mm = 1:324
if (kk==1) && (kk==mm)
Structure_Global_Stiffness{kk,kk} = K_TANK_TOTAL{kk,1};
Structure_Global_Stiffness{kk,kk+1} = K_TANK_TOTAL{kk,2};
elseif (kk==mm) && (kk<98)
Structure_Global_Stiffness{kk,kk-1} = K_TANK_TOTAL{kk,1};
Structure_Global_Stiffness{kk,kk} = K_TANK_TOTAL{kk,2} + K_TANK_TOTAL{kk+1,1};
Structure_Global_Stiffness{kk,kk+1} = K_TANK_TOTAL{kk+1,2};
elseif (kk==mm) && (kk==98)
Structure_Global_Stiffness{kk,kk-1} = K_TANK_TOTAL{kk,1};
Structure_Global_Stiffness{kk,kk} = K_TANK_TOTAL{kk,2} + K_TANK_TOTAL{kk+1,1} + K_TANK_TOTAL{197,1};
Structure_Global_Stiffness{kk,kk+1} = K_TANK_TOTAL{kk+1,2};
Structure_Global_Stiffness{kk,kk+2} = K_TANK_TOTAL {197,2};
elseif (kk==mm) && (kk>98) && (kk<324)
Structure_Global_Stiffness{kk,kk-1} = K_TANK_TOTAL{kk,1};
Structure_Global_Stiffness{kk,kk} = K_TANK_TOTAL{kk,2} + K_TANK_TOTAL{kk+1,1};
Structure_Global_Stiffness{kk,kk+1} = K_TANK_TOTAL{kk+1,2};
elseif (kk==mm) && (kk==324)
Structure_Global_Stiffness{kk,kk-1} = K_TANK_TOTAL{kk,1};
Structure_Global_Stiffness{kk,kk} = K_TANK_TOTAL{kk,2};
else
Structure_Global_Stiffness{kk,zz} = Matrix_0; % HERE I HAVE MY PROBLEM
end
end
end
how can I solve this?
Thank you!
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Communications Toolbox 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!