matlab利用图片矩阵画图,matlab 根据邻接矩阵作图【借鉴实操】

《matlab 根据邻接矩阵作图【借鉴实操】》由会员分享,可在线阅读,更多相关《matlab 根据邻接矩阵作图【借鉴实操】(4页珍藏版)》请在人人文库网上搜索。

1、Matlab中根据邻接矩阵做图function tu_plot(rel,control)%由邻接矩阵画图%输入为邻接矩阵,必须为方阵;%第二个输入为控制量,0表示无向图,1表示有向图。默认值为0r_size=size(rel);if nargin2control=0;endif r_size(1)=r_size(2)disp(Wrong Input! The input must be a square matrix!);return;endlen=r_size(1);rho=10;%限制图尺寸的大小r=2/1.05len;%点的半径theta=0:(2*pi/len):2*pi*(1-1/l。

2、en);pointx,pointy=pol2cart(theta,rho);theta=0:pi/36:2*pi;tempx,tempy=pol2cart(theta,r);point=pointx,pointy;hold onfor i=1:lentemp=tempx,tempy+point(i,1)*ones(length(tempx),1),point(i,2)*ones(length(tempx),1);plot(temp(:,1),temp(:,2),r);text(point(i,1)-0.3,point(i,2),num2str(i);%画点endfor i=1:lenfor j。

3、=1:lenif rel(i,j)link_plot(point(i,:),point(j,:),r,control);%连接有关系的点endendendset(gca,XLim,-rho-r,rho+r,YLim,-rho-r,rho+r);axis off%function link_plot(point1,point2,r,control)%连接两点temp=point2-point1;if (temp(1)&(temp(2)return;%不画子回路;endtheta=cart2pol(temp(1),temp(2);point1_x,point1_y=pol2cart(theta,r。

4、);point_1=point1_x,point1_y+point1;point2_x,point2_y=pol2cart(theta+(2*(thetapi)-1)*pi,r);point_2=point2_x,point2_y+point2;if controlarrow(point_1,point_2);elseplot(point_1(1),point_2(1),point_1(2),point_2(2);end%function arrow(start,stop,l)%start,stop分别为起点和终点%l为箭头的线长度,默认为主线长的1/10t=0.1;ang=15/180*pi。

5、;temp=stop(1)-start(1)+j*(stop(2)-start(2);L=abs(temp);P=angle(temp);if nargin3l=t*L;endp1=P-ang;p2=P+ang;a=stop(1)-l*cos(p1) stop(2)-l*sin(p1);b=stop(1)-l*cos(p2) stop(2)-l*sin(p2);hold onplot(start(1) stop(1),start(2) stop(2);plot(a(1) stop(1),a(2) stop(2);plot(b(1) stop(1),b(2) stop(2);end效果图如下:邻接矩阵为0 1 0 0 0 00 0 0 0 0 11 0 0 0 0 10 0 1 1 0 10 1 0 0 0 11 0 0 0 1 0的有向图:小程序,小兴趣。欢迎加入编程爱好者群(69321895)一起成长。4文书#借鉴。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值