Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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). 
like image 395
user1012017 Avatar asked Apr 10 '26 06:04

user1012017


1 Answers

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

like image 53
John Colby Avatar answered Apr 12 '26 02:04

John Colby



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!