Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Complex Matrix indexing
Replies: 0

 Search Thread: Advanced Search

 walter Mulvany Posts: 14 Registered: 10/19/13
Complex Matrix indexing
Posted: Oct 22, 2013 9:36 AM
 Plain Text Reply

This program is about finite element analysis of a bar element, and I have to input a number of nodes that have x,y coordinates, a number of member that have a connectivity between those nodes ( node a to node b or just columns 2 and 3 in matrix conn). Example, element 1 goes from node 5 to node 2, element 11 goes from node 6 to node 7.
What I need to do is to go to element 1, read the value of (conn - column 2) which is 5, go to the coord matrix, find the value (5) in its column 1 and extract the x value that correspond to that location (5) from (coord - column 2) which in this case is (1).

conn=[1,5,2;2,2,3;3,3,4;4,4,7;5,3,7;6,3,6;7,6,2;8,5,2;9,1,5;10,5,6;11,6,7];
disp ('Elem # Node(a) Node(b)')
disp(conn)
coord=[1,0,0;2,2,0;3,4,0;4,6,0;5,1,1;6,3,1,;7,5,1];
disp ('Node # Xcoord Ycoord')
disp(coord)
M=zeros(length(conn),4);
for i=1:length(conn),
M(i,:)=[conn(i,:) conn(find(conn(:,1)==conn(i,1)),:)];
end

The final matrix should look like this:

Elem From To ax ay bx by
1 4 2 0 0 2 0
2 2 3 2 0 4 0
3 3 4 4 0 6 0
4 4 7 6 0 5 1
5 3 7 4 0 5 1
6 3 6 4 0 3 1
7 6 2 3 1 2 0
8 5 2 1 1 2 0
9 1 5 0 0 1 1
10 5 6 1 1 3 1
11 6 7 3 1 5 1

© The Math Forum at NCTM 1994-2018. All Rights Reserved.