-
Notifications
You must be signed in to change notification settings - Fork 0
/
assocNeighbours.m
49 lines (36 loc) · 1.51 KB
/
assocNeighbours.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
43
44
45
46
47
48
49
function nodeUpdated = assocNeighbours(node, connectionMatrix)
% ASSOCNEIGHBOURS Set the array "input" in the NODE structure-array according to the
% network structure defined in CONNECTIONMATRIX.
%
% ASSOCNEIGHBOURS(NODE, CONNECTIONMATRIX) updates the fields "input" in the NODE
% stucture-array according to the CONNECTIONMATRIX.
%
% Input:
% node - 1 x n structure-array containing node information
% connectionMatrix - n x n adjacent matrix (defined as in graph theory)
%
% Output:
% nodeUpdated - 1 x n sturcture-array with updated node information ("input" fields)
%
% Author: Christian Schwarzer - SSC EPFL
% CreationDate: 8.11.2002 LastModified: 20.01.2003
if(nargin == 2)
if(length(node) ~= length(connectionMatrix))
error('ConnectionMatrix does not correspond to NodeMatrix. Wrong dimension.')
end
nodeUpdated = node;
for i=1:length(node)
nodeUpdated(i).input = [];
indices = find(connectionMatrix(:,i));
% get number of incoming connections from a particular node (multiplicity)
for k=1:length(indices)
multiplicity(k) = connectionMatrix(indices(k),i);
end
% set input vector
for m=1:length(indices)
nodeUpdated(i).input = [nodeUpdated(i).input repmat(indices(m),1,multiplicity(m))];
end
end
else
error('Wrong number of arguments. Type: help assocNeighbours')
end