-
Notifications
You must be signed in to change notification settings - Fork 0
/
countTransitionsPerNode.m
40 lines (28 loc) · 1.06 KB
/
countTransitionsPerNode.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
function nbChangesPerNode = countTransitionsPerNode(tsm)
% COUNTTRANSITIONSPERNODE Count number of changes of a node through evolution.
%
% COUNTTRANSITIONSSPERNODE(TSM) counts for all nodes in TSM how many times they have changed state
% over all discrete timesteps.
%
% Input:
% tsm - n x k+1 matrix containing node-states for n nodes at k timesteps
%
% Output:
% nbChangesPerNode - Number of changes of each node (column vector)
%
% Author: Christian Schwarzer - SSC EPFL
% CreationDate: 27.11.2002 LastModified: 20.01.2003
if(nargin == 1)
nbChangesPerNode = zeros(length(tsm(:,1)),1);
% compare step by step node states at j and j-1
for j=2:length(tsm(1,:))
temp = tsm(:,j) - tsm(:,j-1);
indices = find(temp);
% count number of changes
for k=1:length(indices)
nbChangesPerNode(indices(k)) = nbChangesPerNode(indices(k)) + 1;
end
end
else
error('Wrong number of arguments. Type: help countTransitionsPerNode');
end