Hey ankana,
If I understood your question correctly you're trying to simulate a link status matrix based on a probabilistic model, where links between nodes are established based on a threshold and node activity status.
Based on this assumption and my understanding the issue in the code is that ni and nj are not defined.
Assuming
- All nodes are active (ni = 1 for all i).
- m is the threshold probability for link formation.
A few changes in the code should provide the correct result:
nodes = 3;
m = 0.7;
l = zeros(nodes); % Initialize link matrix
n = ones(1, nodes); % Assume all nodes are active (ni = 1 for all i)
for i = 1:nodes
for j = i+1:nodes
test = unifrnd(0,1);
if n(i) == 1 && n(j) == 1
if test <= m
l(i,j) = 1;
else
l(i,j) = 0;
end
l(j,i) = l(i,j); % Symmetric link
end
end
end
L = l; % Final link status matrix
disp(L);
I hope this resolves the issue!