Cell array variable problem

조회 수: 2 (최근 30일)
Marcelo Boldt
Marcelo Boldt 2020년 9월 25일
댓글: Marcelo Boldt 2020년 9월 25일
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