Replacing old version graphshortestpath with new shortestpath function

37 vues (au cours des 30 derniers jours)
Jeff Boker
Jeff Boker le 30 Nov 2022
Commenté : Walter Roberson le 12 Oct 2023
I am using source code from an old repo and I am trying to replace their graphshortestpath() function with the newer shortestpath(). I went through both documentations and the inputs are graph, source, and target.
Currently, this is the line of code that is undefined since graphshortestpath() does not exist in matlab:
[ dist,path{1} ] = graphshortestpath( adjMatrix, 1, numel(newImg(:)));
The inputs are adjMatrix is 10710x10710 double (sparse), and newImg is 105x102 double. I tried replacing graphshortestpath() with shortestpath() and matlab still says the function is undefined.
Undefined function 'shortestpath' for input arguments of type 'double'.
Error in getHyperReflectiveLayers (line 68)
[ dist,path{1} ] = shortestpath( adjMatrix, 1, numel(newImg(:)));

Réponses (3)

TENG LIU
TENG LIU le 12 Oct 2023
Modifié(e) : TENG LIU le 12 Oct 2023
Are you trying to use the Caserel segmentation code?
I have a solution for those bugs (It is truly annoying for the removal of the old code),
The commented part is the old code, the newer in the below:
% [ dist,path{1} ] = graphshortestpath( adjMatrix, 1, numel(newImg(:)));
path{1} = shortestpath(graph(adjMatrix,'upper'), 1, numel(newImg(:)));
GLHF!

Catalytic
Catalytic le 30 Nov 2022
Modifié(e) : Catalytic le 30 Nov 2022
I tried replacing graphshortestpath() with shortestpath() and matlab still says the function is undefined.
A strange thing to do. What are the odds that the shortestpath() command would have the exact same input syntax as some arbitrary 3rd party function?
[ dist,path{1} ] = shortestpath( graph(adjMatrix), 1, numel(newImg(:)));
  3 commentaires
TENG LIU
TENG LIU le 12 Oct 2023
Not only the graphshortestpath is removed by MatLab, the biograph is also removed by Matlab recently (2022b looks like).
Steven Lord
Steven Lord le 12 Oct 2023
Yes, the biograph object was removed in release R2022b according to the Bioinformatics Toolbox Release Notes. We started warning (in the Release Notes and in the documentation) about the impending removal starting in release R2021b. The graph and digraph classes that supersede it were introduced in release R2015b.
As stated on that Release Notes page, most if not all of the functionality that biograph provided is also provided by the graph and/or digraph objects in core MATLAB. There is one item in that table that is kind of missing: a replacement for dolayout is specifying the Layout name-value argument when you plot the graph or digraph or to call the layout function on the graphics handle returned by plot when called with a graph or digraph input.
If there is functionality that you were able to use with biograph that you cannot do with graph or digraph please let us know.

Connectez-vous pour commenter.


Christine Tobler
Christine Tobler le 12 Oct 2023
You can replace
[ dist,path{1} ] = graphshortestpath( adjMatrix, 1, numel(newImg(:)));
with
[ path{1}, dist ] = shortestpath( digraph(adjMatrix), 1, numel(newImg(:)));
in your code. If the graph being defined by adjMatrix is undirected, you can instead call graph(adjMatrix) - the default of graphshortestpath was to assume a directed graph, but if adjMatrix is symmetric both methods have the same behavior.
  1 commentaire
Walter Roberson
Walter Roberson le 12 Oct 2023
numel(newImg(:)) should be the same as numel(newImg)
(For all but some very odd class redefinitions of subsref or using matlab.mixin.indexing.RedefinesParen class )

Connectez-vous pour commenter.

Catégories

En savoir plus sur Networks dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by