简体   繁体   中英

Add values to specific points in MATLAB

In order to create the global stiffness matrix of a truss, I need to overlay the stiffness matrix to the global one. I started by creating a zero matrix

K=zeros(6,6); %Empty global stiffness matrix

And then I want to overlay a 4x4 matrix (Ke) to the correct position. For example:

Ke(1,1)->K(1,1)
Ke(1,2)->K(1,2)
Ke(1,3)->K(1,5)
Ke(1,4)->K(1,6)
Ke(2,1)->K(2,1)
Ke(2,2)->K(2,2)
Ke(2,3)->K(2,5)
Ke(2,4)->K(2,6)
etc.

I found a piece of code that would work but I'm afraid I can't understand why. Here it is:

sctr = [2*n1-1 2*n1 2*n2-1 2*n2];
K(sctr,sctr) = K(sctr,sctr) + Ke;

Following my above example n1 , n2 should be n1=1 and n2=3 . The n1 and n2 correspond to the start and finish node of the element. Of course this would be inside a loop that will calculate the stiffness matrix of each element and overlay it to the global matrix.

For the given values of n1 and n2 , sctr is

sctr = [1 2 5 6];

This corresponds with the row and column indices you want to change. K(sctr,sctr) selects the 4x4 submatrix of K . Matlab selects one element for each possible combination of the elements in sctr . So, for each selected row (ie which have their index in sctr ) the columns with their index in sctr are selected. See matrix indexing for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM