- 1、本文档共5页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
matlab根据邻接矩阵作图.
Matlab中根据邻接矩阵做图functiontu_plot(rel,control)%由邻接矩阵画图%输入为邻接矩阵,必须为方阵;%第二个输入为控制量,0表示无向图,1表示有向图。默认值为0r_size=size(rel);ifnargin2control=0;endifr_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.05^len;%点的半径theta=0:(2*pi/len):2*pi*(1-1/len);[pointx,pointy]=pol2cart(theta,rho);theta=0:pi/36:2*pi;[tempx,tempy]=pol2cart(theta,r);point=[pointx,pointy];hold onfori=1:len temp=[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)); %画点endfori=1:lenfor j=1:lenifrel(i,j)link_plot(point(i,:),point(j,:),r,control); %连接有关系的点endendendset(gca,XLim,[-rho-r,rho+r],YLim,[-rho-r,rho+r]);axis off%%functionlink_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);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;temp=stop(1)-start(1)+j*(stop(2)-start(2));L=abs(temp);P=angle(temp);ifnargin3 l=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)];holdonplot([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 000 0 0000 1 1 0 000 1 0 0 1 1 0 1 0 1 0 00 1 1 0 00 1 0的有向图:小程序,小兴趣。欢迎加入编程爱好者群一起成长。
文档评论(0)