Dear,
I'm trying to find all short paths between vertices so I used graphallshortestpaths,
but for my matrix
A=[1 1 0 0 1 1 1 1 0 0 0 0 0 1 0 0 0 1 1 1 1 0 0 0 0];
I got error for using the command
graphallshortestpaths(A)Error using graphalgsInput argument should be a sparse array.Error in graphallshortestpaths (line 85) dist = graphalgs('all',debug_level,directed,G);Error in FitnessDiameter (line 92)p=graphallshortestpaths(A)
so I used this code
[r,c]=find(A);edgelist=[r,c];edgelist = unique(edgelist, 'rows');sz = max(edgelist(:));DG = sparse(edgelist(:,1), edgelist(:,2), 1, sz, sz);% correct
matrix=full(DG)%view(biograph(DG,[],'ShowWeights','on'));
p=graphallshortestpaths(DG)
I got result, but I got this matrix
P = [0 1 2 3 1 1 0 1 2 2 3 4 0 1 2 2 3 1 0 1 1 2 3 4 0];
and its wrong because the result should be symmetric matrix.
P = [0 1 2 3 1 1 0 1 2 1 2 1 0 1 2 3 2 1 0 1 1 1 2 1 0];
I don't know why.
It doesn't mentioned which type of matrix this command work. I have sparse matrix, and I want to find all short paths so I can find the diameter.
can anyone help me please.
thanks for any help.
Nadia
Best Answer