Cell array variable problem

1 vue (au cours des 30 derniers jours)
Marcelo Boldt
Marcelo Boldt le 25 Sep 2020
Commenté : Marcelo Boldt le 25 Sep 2020
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!

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by