📄 graphy_plot.asv
字号:
clf,
A=[0 1 1 0;0 0 1 1;0 0 0 1;1 0 0 0];%输入邻接矩阵
xy=[0 1;0 0;-1 -0.5;1 -0.5];%顶点坐标
l=1;%控制参数,l=0,画无向图;l~=0,画有向图
p=0.4%控制箭头大小的参数
%graphy_plot(A,xy,1,0.5),
%function y=graphy_plot(A,xy,l,p)
%画矩阵的有向结构图,A为邻接矩阵,xy为顶点坐标,l为控制参数,l=0,画无向图;l~=0,
%画有向图。p为控制箭头大小的参数。
a=-max(abs(xy(:,1)))*1.1;b=max(abs(xy(:,1)))*1.1;
c=-max(abs(xy(:,2)))*1.1;d=max(abs(xy(:,2)))*1.2;
if l==0
gplot(A,xy),axis([a b c d]),hold on,
else if l~=0
U=[ ];V=[ ];X=[ ];Y=[ ];
n=length(A(:,1));
for i=1:n
k=find(A(i,:)~=0);
m=length(k);
if(m~=0)
for j=1:m
u(1)=(xy(k(j),1)-xy(i,1));v(1)=(xy(k(j),2)-xy(i,2));
u(2)=eps; v(2)=eps;U=[u;U];V=[v;V];
X=[[xy(i,1) xy(k(j),1)];X]; Y=[[xy(i,2) xy(k(j),2)];Y];
end
%switch i
% case 1
text(xy(i,1),xy(i,2),['\bullet\leftarrow\fontsize{16}\it{U}',num2str(i)]);
case 2
text(xy(i,1),xy(i,2),['\bullet\leftarrow\fontsize{16}\it{V}',num2str(i)]);
case 3
text(xy(i,1),xy(i,2),['\bullet\leftarrow\fontsize{16}\it{X}',num2str(i)]);
case 4
text(xy(i,1),xy(i,2),['\bullet\leftarrow\fontsize{16}\it{Y}',num2str(i)]);
end
hold on,
end
end
gplot(A,xy),axis([a b c d]),hold on,
h=quiver(X,Y,U,V,p);set(j,'color','red');hold on,
plot(xy(:,1),xy(:,2),'k','markersize',12),hold on,
end
hold off
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -