0

I have the following code that generate a graph from a matrix adj and a set of nodes stored in nodeNames. I have two types of nodes : i node of type S and j node of type O . in nodeNames the nodes of type O are stored first , so from nodeNames{1} to nodeNames{j} are allocated to nodes O .

G = digraph(adj,nodeNames);
for x=1:j 
    v = dfsearch(G,nodeNames{x});
end

the following code allows me to search for all the dfsearch results for nodes of type O, but in this way I only get the last result in the display , I want to get all the intermidiate itterations of the for loop . What is the best way to do that ? Thanks

StamDad
  • 135
  • 8

1 Answers1

1

In generally the lengths of the vectors returned by dfsearch are not going to all be the same length, so v should be store in a cell array using x as the index:

G = digraph(adj,nodeNames);
for x=1:j 
    v{x} = dfsearch(G,nodeNames{x});
end
beaker
  • 16,331
  • 3
  • 32
  • 49
  • You should get a `1 x j` cell array with the results of each call to `dfsearch` in its own cell. Be sure you don't have `v` still hanging around in your workspace by doing `clear v`. – beaker Jul 17 '17 at 21:32