how to generate path matrix?
Afficher commentaires plus anciens
n=3;ri=0.9;lamda=0.7;
config = dec2bin(0:2.^L-1)-'0';
12 13 23
0 0 0
0 0 1 .r2
0 1 0
0 1 1 r1. .r3
1 0 0
1 0 1
1 1 0
1 1 1
consider 3 nodes (i.e., 1,2,3),this is fixed network. 1 is source node,3 is destination node and 2 is intermediate node. the shortest path is 1 to 3, because fixed network 1 is source and 3 is destination.
but i need this
12 13 23 path
0 0 0 0.00
0 0 1 0.00 % there is no connection with source node (that means 1 to 3 there is no path)
0 1 0 r1r3
0 1 1 r1r3
1 0 0 0.00 % there is no connection with destination node(that means 1 to 3 not connected)
1 0 1 r1r2r3
1 1 0 r1r3
1 1 1 r1r3
please to generate above table. please help me.
Réponses (1)
Tejas
le 15 Juil 2025
Hello Ankanna,
To achieve the desired workflow, follow these steps:
- Start by generating all the paths.
n = 3; L = 3;
allPaths = dec2bin(0:2^L-1) - '0';
expr = cell(size(allPaths,1), 1);
- Find the relevant expression for each path.
for i = 1:size(allPaths,1)
adj = zeros(n);
% If link 1-2 exists
if allPaths(i,1)==1
adj(1,2) = 1; adj(2,1) = 1;
end
% If link 1-3 exists
if allPaths(i,2)==1
adj(1,3) = 1; adj(3,1) = 1;
end
% If link 2-3 exists
if allPaths(i,3)==1
adj(2,3) = 1; adj(3,2) = 1;
end
if adj(1,3)
expr{i} = 'r1r3';
elseif adj(1,2) && adj(2,3)
expr{i} = 'r1r2r3';
else
expr{i} = '0.00';
end
end
- Store the data in Table format.
T = table(allPaths(:,1), allPaths(:,2), allPaths(:,3), expr, ...
'VariableNames', {'12', '13', '23', 'path'})
Catégories
En savoir plus sur Networks dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!