Question about adjacent matrix of a network using MATLAB
Afficher commentaires plus anciens
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 commentaires
Paulo Silva
le 29 Jan 2011
Why do you accept your own answers? You are supposed to accept those answers who are most helpful, not your own extra information!
yuen
le 29 Jan 2011
Réponses (2)
Paulo Silva
le 29 Jan 2011
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])
Paulo Silva
le 29 Jan 2011
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 commentaires
yuen
le 29 Jan 2011
Paulo Silva
le 29 Jan 2011
doc gplot
yuen
le 29 Jan 2011
yuen
le 17 Fév 2011
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!