Matlab draw a graph from the incident matrix

Is there a way to draw a graph from the incident matrix. By schedule, I mean http://en.wikipedia.org/wiki/Graph_(mathematics ), not a chart.

So far, I have only found how to convert the incidence matrix to the adjacency matrix. In R, this is possible with the igraph library. So there is an easy way to do this in matlab

+4
source share
3 answers

You can use gplot :

 k = 1:30; [B,XY] = bucky; gplot(B(k,k),XY(k,:),'-*') axis square 

This feature is commonly used in machine learning problems. During the search, I saw an implementation for building a weighted graph .

enter image description here http://www.mathworks.com/help/matlab/ref/gplot.html

EDIT:

 dt = 2*pi/10; t = dt:dt:2*pi; x = cos(t); y = sin(t); A = ones(10); gplot(A,[x' y']); A = ones(3,3); gplot(A,[x' y']); a = [0 1 1; 1 0 0; 1 1 0]; gplot(a,[x' y'] ,'-*'); 

All you have to do is make sure that the XY plane has enough (x, y) pairs for each node on your graph.

Here is A gplot :

enter image description here

+6
source

ARROW GRAPHS

All previous answers relate to graphs, not taking into account whether the graph is straight or not. I mean, it is possible that if there is an edge (i, j), then the edge (j, i) does not exist. Keep this in mind using the following code:

 % This figure will be used to plot the structure of the graph represented % by the current A matrix. figure dt = 2*pi/N_robots; t = dt:dt:2*pi; x = cos(t); y = sin(t); agents=[ 2 2.5; 0.5 2.0; 0.5 1.0; 2.0 0.5; 3.5 1.0; 3.5 2.0;]; agents = p0; agents = [x' y']; % plot(agents(:,1),agents(:,2),'s','MarkerSize', 20, 'MarkerFaceColor', [1 0 1]) grid on %xlim([0 4]) %ylim([0 3]) hold on index=1; % The following prints the non-directed graph corresponding to the A matrix for i=1:N_robots for j=index:N_robots if A(i,j) == 1 arrowline(agents([ij],1),agents([ij],2),'arrowsize',600); % plot(agents([ij],1),agents([ij],2),'--','LineWidth',2.5); end end end set(gca,'FontSize',fontsize2) title('Structure of the Graph','interpreter', 'latex','FontSize', 18) 

You can get the following result: enter image description here

Currently it works for 6 agents. I did not have time to check the total number of agents, but in principle this should work. You can use a different agent for this.

Hope this helps you.

+3
source

Here is a solution that uses a matrix like yours

 % Define a matrix A. A = [0 1 1 0 ; 1 0 0 1 ; 1 0 0 1 ; 0 1 1 0]; % Draw a picture showing the connected nodes. cla subplot(1,2,1); gplot(A,[0 1;1 1;0 0;1 0],'.-'); text([-0.2, 1.2 -0.2, 1.2],[1.2, 1.2, -.2, -.2],('1234')', ... 'HorizontalAlignment','center') axis([-1 2 -1 2],'off') % Draw a picture showing the adjacency matrix. subplot(1,2,2); xtemp=repmat(1:4,1,4); ytemp=reshape(repmat(1:4,4,1),16,1)'; text(xtemp-.5,ytemp-.5,char('0'+A(:)),'HorizontalAlignment','center'); line([.25 0 0 .25 NaN 3.75 4 4 3.75],[0 0 4 4 NaN 0 0 4 4]) axis off tight 

Taken from the example about bucky http://www.mathworks.nl/products/matlab/examples.html;jsessionid=59c5cf7261bdf09589f79bab2bc2?file=/products/demos/shipping/matlab/buckydem.html

+2
source

Source: https://habr.com/ru/post/1445060/


All Articles