-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathmeshconn.m
42 lines (41 loc) · 1.04 KB
/
meshconn.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function [conn, connnum, count] = meshconn(elem, nn)
%
% [conn,connnum,count]=meshconn(elem,nn)
%
% create node neighbor list from a mesh
%
% author: Qianqian Fang, <q.fang at neu.edu>
% date: 2007/11/21
%
% input:
% elem: element table of a mesh
% nn : total node number of the mesh
%
% output:
% conn: output, a cell structure of length nn, conn{n}
% contains a list of all neighboring node ID for node n
% connnum: vector of length nn, denotes the neighbor number of each node
% count: total neighbor numbers
%
% -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
%
conn = cell(nn, 1);
dim = size(elem);
for i = 1:dim(1)
for j = 1:dim(2)
conn{elem(i, j)} = [conn{elem(i, j)}, elem(i, :)];
end
end
count = 0;
connnum = zeros(1, nn);
for i = 1:nn
if (length(conn{i}) == 0)
continue
end
% conn{i}=sort(setdiff(unique(conn{i}),i));
neig = unique(conn{i});
neig(neig == i) = [];
conn{i} = neig;
connnum(i) = length(conn{i});
count = count + connnum(i);
end