跪求解释 Matlab中graphshortestpath的具体用法 需要什么参数,矩阵,得到什么结果?
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/10 12:06:04
跪求解释 Matlab中graphshortestpath的具体用法 需要什么参数,矩阵,得到什么结果?
是一个最短路径问题,据说是封装好的floyd,Dijkstra 算法
最短路径问题是有权还是没权问题呢?
是一个最短路径问题,据说是封装好的floyd,Dijkstra 算法
最短路径问题是有权还是没权问题呢?
我看了一下这个函数的例子
默认是Dijkstra 算法
是有权的, 我想如果把权都赋1的话, 就相当于没权的了
参数是带权的稀疏矩阵及结点
看看这两个例子(一个有向一个无向), 或许你能找到你想知道的
% Create a directed graph with 6 nodes and 11 edges
W = [.41 .99 .51 .32 .15 .45 .38 .32 .36 .29 .21]; %这是权
DG = sparse([6 1 2 2 3 4 4 5 5 6 1],[2 6 3 5 4 1 6 3 4 3 5],W) %有权的有向图
h = view(biograph(DG,[],'ShowWeights','on')) %画图, 这个好玩
% Find shortest path from 1 to 6
[dist,path,pred] = graphshortestpath(DG,1,6) %找顶点1到6的最短路径
% Mark the nodes and edges of the shortest path
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) %上色
下面是无向图的例子
% % Solving the previous problem for an undirected graph
% UG = tril(DG + DG')
% h = view(biograph(UG,[],'ShowArrows','off','ShowWeights','on'))
% % Find the shortest path between node 1 and 6
% [dist,path,pred] = graphshortestpath(UG,1,6,'directed',false)
% % Mark the nodes and edges of the shortest path
% set(h.Nodes(path),'Color',[1 0.4 0.4])
% fowEdges = getedgesbynodeid(h,get(h.Nodes(path),'ID'));
% revEdges = getedgesbynodeid(h,get(h.Nodes(fliplr(path)),'ID'));
% edges = [fowEdges;revEdges];
% set(edges,'LineColor',[1 0 0])
% set(edges,'LineWidth',1.5)
%
对matlab我只知皮毛, 只是对你这个问题感兴趣而已(以前学过), 可别怪我没答到点子上哈
默认是Dijkstra 算法
是有权的, 我想如果把权都赋1的话, 就相当于没权的了
参数是带权的稀疏矩阵及结点
看看这两个例子(一个有向一个无向), 或许你能找到你想知道的
% Create a directed graph with 6 nodes and 11 edges
W = [.41 .99 .51 .32 .15 .45 .38 .32 .36 .29 .21]; %这是权
DG = sparse([6 1 2 2 3 4 4 5 5 6 1],[2 6 3 5 4 1 6 3 4 3 5],W) %有权的有向图
h = view(biograph(DG,[],'ShowWeights','on')) %画图, 这个好玩
% Find shortest path from 1 to 6
[dist,path,pred] = graphshortestpath(DG,1,6) %找顶点1到6的最短路径
% Mark the nodes and edges of the shortest path
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) %上色
下面是无向图的例子
% % Solving the previous problem for an undirected graph
% UG = tril(DG + DG')
% h = view(biograph(UG,[],'ShowArrows','off','ShowWeights','on'))
% % Find the shortest path between node 1 and 6
% [dist,path,pred] = graphshortestpath(UG,1,6,'directed',false)
% % Mark the nodes and edges of the shortest path
% set(h.Nodes(path),'Color',[1 0.4 0.4])
% fowEdges = getedgesbynodeid(h,get(h.Nodes(path),'ID'));
% revEdges = getedgesbynodeid(h,get(h.Nodes(fliplr(path)),'ID'));
% edges = [fowEdges;revEdges];
% set(edges,'LineColor',[1 0 0])
% set(edges,'LineWidth',1.5)
%
对matlab我只知皮毛, 只是对你这个问题感兴趣而已(以前学过), 可别怪我没答到点子上哈
跪求解释 Matlab中graphshortestpath的具体用法 需要什么参数,矩阵,得到什么结果?
matlab中abs(A)其中A是一个矩阵,得到什么结果啊
matlab编写的函数,当传输参数为矩阵时,运行总是出错,跪求大神解释
MATLAB中,积分后得到数值多项式,用什么命令得到一个具体的数值啊?
MATLAB中相关系数矩阵和协方差矩阵的命令?这两个矩阵有什么区别,不用命令怎么求
请问MATLAB中求复数矩阵对应的行列式值用什么函数?
matlab中rand函数的具体用法
matlab中feval的具体用法
用什么命令取matlab中矩阵的第一列
MATLAB里求矩阵的秩用什么语句?
MATLAB中strel函数的作用以及用法参数是什么?
求family的具体用法,在什么情况时才真正需要加S?