user1012017
user1012017

Reputation: 41

dijkstra algorithm using Matlab

I am doing dijkstra algorithm using Matlab . Here is my code

W = [10 8 5 3 7 2 4 6 21];
DG = sparse([1 1 1 2 2 3 4 5 6],[2 4 3 4 5 6 6 6 1],W)

h = view(biograph(DG,[],'ShowWeights','on'))

[dist,path,pred] = graphshortestpath(DG,1,6)

set(h.Nodes(path),'Color',[1 0.4 0.4])
edges = getedgesbynodeid(h,get(h.Nodes(path),'ID'));
set(edges,'LineColor',[1 0 0])
set(edges,'LineWidth',1.5)

The problem is how do i get the red color lines nodes and edges of the shortest path "reset". for example I want it to be [dist,path,pred] = graphshortestpath(DG,2,3) but the graph still shows the

[dist,path,pred] = graphshortestpath(DG,1,6). 

Upvotes: 3

Views: 6211

Answers (1)

John Colby
John Colby

Reputation: 22588

This will do it:

set(h.edges, 'LineColor', [0.5 0.5 0.5])
set(h.edges, 'LineWidth', 0.5)
set(h.nodes, 'Color', [1 1 0.7])

You can inspect all the other properties you can change by simply doing get(h).

There is also some good online info about setting properties of biograph objects:

http://www.mathworks.com/help/toolbox/bioinfo/ref/setbiograph.html

Upvotes: 1

Related Questions