作业帮 > 综合 > 作业

如何用matlab画出有向图(带箭头),例如下图

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/21 09:05:50
如何用matlab画出有向图(带箭头),例如下图
/>close all,clear,clc;
cm =[ 
     0     10     0     18     0     0     0;
     0     0      0     0      8     0     0;
     25    0      0     0      0     9     0;
     0     0      0     0      0     0     0;
     0     0      13    0      0     0     0;
     0     0      0     30     0     0     0;
     0     0      0     0      15    12    0;
     ];
 IDS={'A','B','C','D','E','F','G'};
 bg=biograph(cm,IDS);
 set(bg.nodes,'shape','circle','color',[1,1,1],'lineColor',[0,0,0]);
 set(bg,'layoutType','radial');
 bg.showWeights='on';
 set(bg.nodes,'textColor',[0,0,0],'lineWidth',2,'fontsize',9);
 set(bg,'arrowSize',12,'edgeFontSize',9);
 get(bg.nodes,'position')
 view(bg);
 help biograph
显示出来后,自己手动用鼠标拖动结点位置使好看,右键用refresh edges选项.


再问: 可不可以自己给出每个点的坐标然后画有向图
再答:
close all,clear,clc;
cm =[ 
     0     10     0     18     0     0     0;
     0     0      0     0      8     0     0;
     25    0      0     0      0     9     0;
     0     0      0     0      0     0     0;
     0     0      13    0      0     0     0;
     0     0      0     30     0     0     0;
     0     0      0     0      15    12    0;
     ];
 IDS={'A','B','C','D','E','F','G'};
 bg=biograph(cm,IDS);
 set(bg.nodes,'shape','circle','color',[1,1,1],'lineColor',[0,0,0]);
 set(bg,'layoutType','radial');
 bg.showWeights='on';
 set(bg.nodes,'textColor',[0,0,0],'lineWidth',2,'fontsize',9);
 set(bg,'arrowSize',12,'edgeFontSize',9);
 get(bg.nodes,'position')
 dolayout(bg);
 bg.nodes(1).position=[100,200];
 bg.nodes(2).position=[50,100];
 bg.nodes(3).position=[100,100];
 bg.nodes(4).position=[150,100];
 bg.nodes(5).position=[0,0];
 bg.nodes(6).position=[200,0];
 bg.nodes(7).position=[100,0];
 dolayout(bg,'pathsonly',true);
 
 view(bg);
 help biograph这是用指定点坐标画的图: