# Plotting a 3D matrix graph

조회 수: 8 (최근 30일)
Bhavz . 2014년 8월 24일
댓글: Bhavz . 2014년 8월 26일
How would i plot the above links/edges vs a value fval that i am obtaining through my coding program in a 3D matrix graph or some other graph which is feasible in my case .Please do help as I have been stuck with this for ages

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

### 채택된 답변

Matz Johansson Bergström 2014년 8월 24일
편집: Matz Johansson Bergström 님. 2014년 8월 24일
First, I assume that the graph is undirected, edges are going both ways, but you might want to change that maybe.
A = zeros(13, 13); %adjacency matrix, assume undirected graph
A(inds) = 1; %the points are connected
%Making A symmetric (undirected graph)
A = triu(A, 1);
A = A + A';
%Positioning the nodes in a circle
x = cos(theta);
y = sin(theta);
gplot(A, [x' y'], 'o-')
hold on
%Put text at the nodes
scale = 1.07; %radius of the text positions
for i = 1:size(A,1)
if sum(A(i,:)) > 0 %if there are any links
text(scale*x(i), scale*y(i), num2str(i), 'fontsize', 16,...
'HorizontalAlignment', 'center')%num2str(nums(i)))
end
end
axis([-1.1,1.1,-1.1,1.1])
So, I first create a adjacency matrix from the links you provided. Then I give gplot the coordinates to the node positions using a circle, that just seemed to work in this case. If you wish to place the nodes in another position you can give other coordinates to x and y.
I also added text at the node positions so you can easily check that it is correct.
##### 댓글 수: 2이전 댓글 1개 표시이전 댓글 1개 숨기기
Bhavz 2014년 8월 26일
global hd ce Ye delta_edp X_dp;
%primary path
Pd_pr(1,:)=[2, 6, 10];
Pd_pr(2,:)=[3,7,11];
Pd_pr(3,:)=[3,7,12];
Pd_pr(4,:)=[15, 16,0];
%sencondary path
Pd_s(1,:)=[1,4,9];
Pd_s(2,:)=[2,5,9];
Pd_s(3,:)=[3,8,13];
Pd_s(4,:)=[3,8,14];
path=[Pd_pr;Pd_s];
ce=[50 50 200 50 50 50 150 50 50 50 50 50 50 50 50 50];
%demand
demand=[1 10;1 11;1 12;1 13];
%associated flow values for demand
hd=[50 50 50 50];
%value of X_dp
X_dp=zeros(4,8);
for jj=1:4
for kk=1:8
demandStart=demand(jj,1);
demandEnd=demand(jj,2);
pathStart=path(kk,1);
pathEnd=path(kk,3);
if pathEnd==0
pathEnd=path(kk,2);
end
if pathEnd==0
pathEnd=path(kk,2);
end
X_dp(jj,kk)=1;
end
end
end
X_dp1=reshape(X_dp,1,[]);
%value of delat_edp
delta_edp=zeros(16,4,8);
for ii=1 : 16
for jj=1: 4
for kk=1:8
for nn=1:3
if path(kk,nn)==ii && X_dp(jj,kk)==1
delta_edp(ii,jj,kk)=1;
end
end
end
end
end
%value of Ye
Ye=zeros(16,1);
for ii=1:16
for kk=1:4
for nn=1:3
if Pd_pr(kk,nn)==ii
Ye(ii)=1;
end
end
end
end
lb = zeros(1,32); ub=X_dp1;
nonlcon=@constraint; [x,fval,exitflag] = ga(@objectiveFun,... 32,[],[],[],[],lb,ub,nonlcon);
l_dp=reshape(x,4,8)
min_romax=fval
So if thats the code and i want to plot fval value for each link would i still do it the way you suggested

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

### 카테고리

Help CenterFile Exchange에서 Directed Graphs에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!