How to superimpose certain indices of two matrices.
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!