How to superimpose certain indices of two matrices.

조회 수: 3 (최근 30일)
Missael Hernandez
Missael Hernandez 2020년 11월 3일
답변: Ameer Hamza 2020년 11월 3일
Suppose I have matrices K^1 and K^2. I would like to construct a globla stiffness matrix such that wwe add certain indices to construct the globlal matrix. The color coating indicates the elements being added and their corresponding index in the global matrix. How would I do this in Matlab? How would I do it if I had more matices?

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 11월 3일
For two matrices, try
K1 = rand(4);
K2 = rand(4);
Kg = zeros(6);
Kg(1:4, 1:4) = K1;
Kg(3:6, 3:6) = Kg(3:6, 3:6) + K2
For a general case
K1 = rand(4);
K2 = rand(4);
K3 = rand(4);
K4 = rand(4);
K = {K1, K2, K3, K4};
n = 2*numel(K)+2;
Kg = zeros(n);
Kg(1:4, 1:4) = K{1};
for i = 2:numel(K)
Kg(2*i-1:2*i+2, 2*i-1:2*i+2) = Kg(2*i-1:2*i+2, 2*i-1:2*i+2) + K{i};
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by