-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindTriangle.m
More file actions
82 lines (47 loc) · 1.65 KB
/
FindTriangle.m
File metadata and controls
82 lines (47 loc) · 1.65 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
% clear
% A = [1,2,3,4,1,2,1; 2,3,4,5,3,4,5];
% DoubList = A';
function TriList = FindTriangle(DoubList)
%------------------------------------------------------------
% find triangles from double list and then implement to function triFill()
%
% input: double value list
%----------------------------------------------------------
S = DoubList;
Sn = S;
% [sort_S,Idx]= sort(Sn,2,'ascend');
UniA = unique(S(:,1));
TriList=[];
for elmt = UniA'
idx_list = find(Sn(:,1) == elmt);
A_list = Sn(idx_list',:);
if numel(A_list(:,2)) > 1
Res_List = nchoosek(A_list(:,2),2); % permutation and combination
for posib_com = Res_List'
temp_com = [posib_com(1),posib_com(2)];
[LIA,LOCB] = ismember(temp_com,Sn,'rows','legacy');
TriList_tem=[];
if LIA
TriList_tem(1,1) = elmt;
TriList_tem(:,2:3) = temp_com;
TriList=[TriList; TriList_tem];
else
TriList_tem(1,1) = elmt;
TriList_tem(1,2) = posib_com(1);
TriList_tem(1,3) = 0;
TriList_tem(2,1) = elmt;
TriList_tem(2,2) = posib_com(2);
TriList_tem(2,3) = 0;
TriList=[TriList; TriList_tem];
end
end
else
TriList_tem(1,1) = elmt;
TriList_tem(1,2) = A_list(1);
TriList_tem(1,3) = 0;
TriList_tem(2,1) = elmt;
TriList_tem(2,2) = A_list(2);
TriList_tem(2,3) = 0;
TriList=[TriList; TriList_tem];
end
end