Hi Hassan,
To construct a subgraph containing the specified nodes, you can use the MATLAB function "subgraph". The "subgraph" function requires a "graph" object, which can be created by using the "digraph" function applied to the specified sparse adjacency matrix.
The following code snippet illustrates the above workflow:
W = [.41 .99 .51 .32 .15 .45 .38 .32 .36 .29 .21];
DG = sparse([6 1 2 2 3 4 4 5 5 6 1],[2 6 3 5 4 1 6 3 4 3 5],W)
%Create a graph object for the given DG matrix
G = digraph(DG);
% Specify the nodes for the subgraph
selectedNodes = [6, 2, 4];
% Create the subgraph containing only the specified nodes
subG = subgraph(G, selectedNodes)
plot(subG,'EdgeLabel', subG.Edges.Weight);
Please note, that the node numbering in the subgraph is reset.
For more details, please refer to the following MathWorks documentation: https://www.mathworks.com/help/matlab/ref/graph.subgraph.html#:~:text=The%20node%20numbering%20in%20the%20subgraph%20is%20reset
Hope this helps!