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!

采纳的回答

madhan ravi
madhan ravi 2020-9-25
Structure_Global_Stiffness{kk,zz}(~eye(3)) = 0;
  3 个评论
madhan ravi
madhan ravi 2020-9-25
If each cell is 3 x 3 then it’s shouldn’t error out.
Marcelo Boldt
Marcelo Boldt 2020-9-25
the mistake was located in the indexes, i mixed mm for zz! Thanks anyways!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Communications Toolbox 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by