How can i assemble a 4x4 matrix into a 12x12 matrix (Stiffness Matrix)

3 views (last 30 days)
I have 5 elements (k1 to k5) that are 4x4 matrices. I want to use a matlab command to assemble them in a 12x12 matrix depending on the nodes in the element. For each node, is 2 columns and 2 rows (u1, v1, u2, v2). For example, if
k1= [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16]
and is between node 2 and 4, i want it to be in the matrix from (u2,v2) to (u4,v4)
When other elements merge, they should add up correspondingly
  2 Comments
Stefan
Stefan on 28 Jun 2015
It is difficult to follow what you actually want. Can you please reformulate your question and correct the typo?

Sign in to comment.

Answers (2)

Thorsten
Thorsten on 28 Jun 2015
To get the first submatrix, you can use
k1= [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16];
u = 2; v = 4;
X = zeros(12);
dvu = v - u;
m = reshape(1:dvu^2, dvu, dvu);
[i j] = ind2sub(size(m), m)
ind = sub2ind(size(X), i + dvu, j + dvu);
x = k1(1:dvu, 1:dvu);
X(ind) = x(:);

Mikhail Persiyanov-Dubrov
Mikhail Persiyanov-Dubrov on 19 Mar 2021
I didn't really understood the question, but i hope the following example answerst it.
K = zeros(12);
k1= [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16];
u = 2; v = 4;
ids = [2*u-1, 2*u, 2*v-1, 2*v];
K(ids,ids) = K(ids,ids) + k1

Community Treasure Hunt

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

Start Hunting!