Replacing old version graphshortestpath with new shortestpath function

38 views (last 30 days)
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(:)));

Answers (3)

TENG LIU
TENG LIU on 12 Oct 2023
Edited: TENG LIU on 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 on 30 Nov 2022
Edited: Catalytic on 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 Comments
TENG LIU
TENG LIU on 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 on 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.

Sign in to comment.


Christine Tobler
Christine Tobler on 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.

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!