Question about adjacent matrix of a network using MATLAB

I would like to know how to using the plot function to show the relationship of an adjacent matrix.It means if I want to connect a matrix, 1 means connected and 0 means no connection. Example, a matrix like this 0 1 0 1 1 0 1 1 0 0 1 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 1 1 0 0 0 1 0 0 0 0 1 1 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 1 1 0 0 1 0 0 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1 1 0 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 1 0 0
I would like to know how to connect those node if they are connected.

댓글 수: 2

Why do you accept your own answers? You are supposed to accept those answers who are most helpful, not your own extra information!
yuen
yuen 2011년 1월 29일
ha..i make an mistake~

댓글을 달려면 로그인하십시오.

답변 (2개)

Paulo Silva
Paulo Silva 2011년 1월 29일
spy([0 1 0 1 1 0 1 1 0 0
1 0 1 0 0 0 0 0 1 0
0 1 0 0 0 0 0 1 0 1
1 0 0 0 1 0 0 0 0 1
1 0 0 1 0 1 0 0 0 0
0 0 0 0 1 0 1 1 0 0
1 0 0 0 0 1 0 0 1 0
1 0 1 0 0 1 0 0 1 1
0 1 0 0 0 0 1 1 0 0
0 0 1 1 0 0 0 1 0 0])

댓글 수: 6

yuen
yuen 2011년 1월 29일
first,thank you for your response.
however, I would like to know how to connect the node if they are connected?
yuen
yuen 2011년 1월 29일
if it is 1, then use a line to make a connection, if 0,no connection. I would like to know how to show it out by matlab? Can you help me? Thank you very much!!=]
coonected? how?
yuen
yuen 2011년 1월 29일
the matrix, 1 is means connection, 0 means no connection..do you understand my question?
yuen
yuen 2011년 1월 29일
for example, [0 1 0 1;1 0 1 1]
for the above matrix, for the first 1, (12) is connected. while (13) is zero, then no connection.
yuen
yuen 2011년 1월 29일
i would like to show it out by using the matlab function, but how? i have no ideas....

댓글을 달려면 로그인하십시오.

Paulo Silva
Paulo Silva 2011년 1월 29일
I wonder if it's this you want?!
%Your matrix is in variable a
hold on
drawlines=1; %1 to connect points where a equals 1
markpoints=0; %1 to mark points where a equals 1
for r=1:numel(a(:,1))
for c=1:numel(a(1,:))
y=numel(a(:,1))-r+1;
x=c;
if((r~=numel(a(:,1))) & (c~=numel(a(1,:))))
if((a(r,c)==1) & (a(r+1,c+1)==1))
if (drawlines==1)
line([x x+1],[y y-1])
end
if (markpoints==1)
plot(x,y,'*')
plot(x+1,y-1,'*')
end
end
end
if((c~=1) & (r~=numel(a(:,1))))
if((a(r,c)==1) & (a(r+1,c-1)==1))
if (drawlines==1)
line([x x-1],[y y-1])
end
if (markpoints==1)
plot(x,y,'*')
plot(x-1,y-1,'*')
end
end
end
end
end
axis([1 numel(a(1,:)) 1 numel(a(:,1))])

댓글 수: 4

yuen
yuen 2011년 1월 29일
OH....really thank you very much!!!But.what factor you based on to plot such graph? becasue i am quite doubt about the result. The graph I plot is not i expected. can i send you a whole matlab script to have a look? I think the connection still have problems. sorry for causing you any inconvenience but i really need your help!
doc gplot
yuen
yuen 2011년 1월 29일
what doc gplot?
yuen
yuen 2011년 2월 17일
hi, i would like to seek your help on the matlab program you have written before, hope you can spend little time.. thanks..

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

질문:

2011년 1월 29일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by