이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
how to extract the value from voronoi diagram in matlab?
조회 수: 6 (최근 30일)
이전 댓글 표시
I need to know how to extract the value from the "voronoi" diagram in matlab. Please reply to me as soon as possible.
I'm plotting this graph by using this command "voronoi". And now I want to extract the value of each "node" in each "cluster".
댓글 수: 2
Geoff Hayes
2014년 9월 3일
Arul - are you doing more than just calling voronoi to get the above plot? What are the lines of code that you are calling to produce the above? The cluster heads are presumably the coordinates for the points passed into the voronoi function, but where do the other ones come from?
채택된 답변
Geoff Hayes
2014년 9월 2일
Arul - if you want to get the vertices for each Voronoi cell, then use voronoin. For example, from this link, [V,C] = voronoin(X) returns Voronoi vertices V and the Voronoi cells C of the Voronoi diagram of X.
댓글 수: 14
Matlab111
2014년 9월 3일
No actually my problem is this http://www.mathworks.in/matlabcentral/answers/153084-how-to-extract-the-neighborhood-node-value-from-this-graph just look at this than try to tell the solution plz.
Geoff Hayes
2014년 9월 3일
The above link is invalid. Can you post the code that you have used to produce the above plot?
Matlab111
2014년 9월 3일
편집: Matlab111
2014년 9월 3일
close all;
clear all;
%Field Dimensions - x and y maximum (in meters)
xm=100;
ym=100;
sink.x=0.5*xm;
sink.y=0.5*ym;
n=100;
p=0.1;
Eo=0.1;
ETX=50*0.000000001;
ERX=50*0.000000001;
Efs=10*0.000000000001;
Emp=0.0013*0.000000000001;
EDA=5*0.000000001;
m=0.1;
x=0.2;
a=1;
b=0.5;
rmax=5;
Ave_CH=0;
sum=0;
count_ch=0;
Throughput=0;
Packet=40;
do=sqrt(Efs/Emp);
figure(1);
for i=1:1:n
S(i).xd=rand(1,1)*xm;
XR(i)=S(i).xd
S(i).yd=rand(1,1)*ym;
YR(i)=S(i).yd
S(i).G=0;
S(i).E=0;
S(i).type='N'
keep(i)=i;
temp_rnd0=i;
if (temp_rnd0>=(x+m)*n+1)
S(i).E=Eo;
S(i).ENERGY=0;
plot(S(i).xd,S(i).yd,'o');
hold on;
end
end
S(n+1).xd=sink.x;
S(n+1).yd=sink.y;
figure(1);
countCHs=0;
rcountCHs=0;
cluster=1;
countCHs;
rcountCHs=rcountCHs+countCHs;
flag_first_dead=0;
flag_first_Hdead=0;
flag_last_dead=0;
c=1;
for r=0:1:rmax
for i=1:1:n
if(S(i).E>0)
holder(i)=S(i).E;
id(i)=keep(i);
node= struct('energy', holder, 'id',id);
[energy,index] = sort([node.energy],'descend');
end
end
total=0;
for k=1:length(node.energy)
energy_level=sort(node.energy, 'descend');
total=total + node.energy(k);
end
average=total/length(node.energy);
TEnergy(r+1)=total;
AveEnergy(r+1)=average;
r
%Election Probability for Normal Nodes
pnrm=( p/ (1+a*m+b*x) );
if(mod(r, round(1/pnrm) )==0)
for i=1:1:n
S(i).G=0;
S(i).cl=0;
end
end
end
Hdead=0;
dead=0;
packets_TO_BS=0;
packets_TO_CH=0;
PACKETS_TO_CH(r+1)=0;
PACKETS_TO_BS(r+1)=0;
figure(1);
for i=1:1:n
if (S(i).E<=(Eo/2)) && (S(i).E>0)
plot(S(i).xd,S(i).yd,'yellow .');
Hdead=Hdead+1;
if(S(i).ENERGY==1)
Hdead_a=Hdead_a+1;
end
hold on;
end
if (S(i).E<=Eo)||(S(i).E>Eo)
if(S(i).ENERGY==0)
RnEnergy(r+1)=S(i).E;
end
end
if (S(i).E<=0)
plot(S(i).xd,S(i).yd,'red .');
dead=dead+1;
if(S(i).ENERGY==1)
dead_a=dead_a+1;
end
hold on;
end
if S(i).E>0
S(i).type='N'
if (S(i).ENERGY==0)
plot(S(i).xd,S(i).yd,'o');
end
hold on;
end
end
plot(S(n+1).xd,S(n+1).yd,'x');
HSTATISTICS(r+1).DEAD=Hdead;
HDEAD(r+1)=Hdead;
if (Hdead==1)
if(flag_first_Hdead==0)
first_Hdead=r;
flag_first_Hdead=1;
end
end
STATISTICS(r+1).DEAD=dead;
DEAD(r+1)=dead;
if (dead==1)
if(flag_first_dead==0)
first_dead=r;
flag_first_dead=1;
end
end
alive=0;
for i=1:1:n
if (S(i).E>0)
alive=alive+1;
if(S(i).ENERGY==1)
alive_a=alive_a+1;
end
hold on;
end
if (S(i).E>0)
nodes_status=1;
end
if (S(i).E<0)
nodes_status=0;
end
ASTATISTICS(r+1).Live=alive;
Live(r+1)=alive;
end
countCHs=0;
cluster=1;
for i=1:1:n
if(S(i).E>0)
temp_rand=rand;
if ( (S(i).G)<=0)
if( ( S(i).ENERGY==0 && ( temp_rand <= ( pnrm / ( 1 - pnrm * mod(r,round(1/pnrm)) )) ) ) )
countCHs=countCHs+1;
packets_TO_BS=packets_TO_BS+1;
PACKETS_TO_BS(r+1)=packets_TO_BS;
S(i).type='C'
S(i).G=100;
C(cluster).xd=S(i).xd
C(cluster).yd=S(i).yd
plot(S(i).xd,S(i).yd,'red+');
distance=sqrt( (S(i).xd-(S(n+1).xd) )^2 + (S(i).yd-(S(n+1).yd) )^2 );
C(cluster).distance=distance
C(cluster).id=i
X(cluster)=S(i).xd
Y(cluster)=S(i).yd
cluster=cluster+1;
distance;
if (distance>do)
S(i).E=S(i).E-((ETX+EDA)*(Packet)+Emp*Packet*( distance*distance*distance*distance ));
Energy_CH_N=(ETX+EDA)*(Packet) + Emp*Packet*( distance*distance*distance*distance );
end
if (distance<=do)
S(i).E=S(i).E- ( (ETX+EDA)*(Packet) + Efs*Packet*( distance * distance ));
Energy_CH_N=(ETX+EDA)*(Packet) + Emp*Packet*( distance*distance);
end
end
end
end
end
warning('OFF');
[vx,vy]=voronoi(X,Y);
voronoi(X,Y);
axis([0 xm 0 ym]);
Geoff Hayes
2014년 9월 3일
Okay - if I run the above code, there always seems to be 101 nodes and a varying number of cells/clusters. If you want to find which nodes belong to which clusters, then just calculate the distance from each node to each cluster "centre" and that distance which is the shortest is the cluster that the node belongs to. Something like
% pre-allocate memory to the node~cluster array
clusterData = cell(size(X,2),1);
% iterate over each node
for k=1:size(S,2)
x = S(k).xd;
y = S(k).yd;
minDist = Inf;
at = 0;
% iterate over each cluster
for u=1:size(X,2)
dist = sqrt((x-X(u))^2+(y-Y(u))^2);
if dist<minDist
% distance is shorter, so the node is closer to this cluster
minDist = dist;
at = u;
end
end
% add the node to the array of clusters
if at>0
clusterData{at} = [clusterData{at} ; S(k)];
end
end
The above code will group each node into the cluster that it belongs. So if there are 12 clusters/cells, then the size of clusterData is 12 with each element having zero or more nodes.
Geoff Hayes
2014년 9월 3일
Arul - you will need to describe (to me) what the cluster head position is. What in your code represents the cluster head? Are the cluster heads different from the input to the call to voronoi at
[vx,vy]=voronoi(X,Y);
Matlab111
2014년 9월 4일
1.'X' and 'Y' represents the cluster head positions.
2. X(cluster)=S(i).xd
Y(cluster)=S(i).yd
3."Are the cluster heads different from the input to the call to voronoi at [vx,vy]=voronoi(X,Y);" -No,the Cluster head is same.
Geoff Hayes
2014년 9월 4일
So, change the above code to the following to get the positions of each cluster head and the positions of each node within that cluster
clusterData = cell(size(X,2),1);
for k=1:size(clusterData)
clusterData{k}.clusterHead = [X(k) Y(k)];
clusterData{k}.clusterNodes = [];
end
for k=1:size(S,2)
x = S(k).xd;
y = S(k).yd;
minDist = Inf;
at = 0;
for u=1:size(X,2)
dist = sqrt((x-X(u))^2+(y-Y(u))^2);
if dist<minDist
minDist = dist;
at = u;
end
end
if at>0
clusterData{at}.clusterNodes = ...
[clusterData{at}.clusterNodes ; [x y] ];
end
end
Now clusterData will be a cell array of structs where each struct has two fields: the clusterHead which is the (x,y) coordinate of the cluster head, and an array of cluster node positions. For example,
clusterData{1}
ans =
clusterHead: [92.0332039836564 5.26769976807926]
clusterNodes: [5x2 double]
and
clusterData{1}.clusterNodes
ans =
72.122749858174 10.6761861607241
68.1971904149063 4.24311375007417
82.5313795402046 8.3469814858914
80.336439160244 6.04711791698936
92.0332039836564 5.26769976807926
Matlab111
2014년 9월 4일
편집: Matlab111
2014년 9월 4일
ya sir i'm getting, now i want to do multihop communication. which means, like this
in this diagram that read color line represent's finding the nearer cluster head by communicating through the neighborhood node. so now i want to find nearer cluster head through the nodes.Display which cluster head is nearer and display other cluster head and display through which node it's finding.
Geoff Hayes
2014년 9월 4일
Arul - please create a new question as what you are requesting (in your above comment) has nothing to do with the original question that began this thread.
Matlab111
2014년 10월 14일
편집: Matlab111
2014년 10월 14일
http://www.mathworks.in/matlabcentral/answers/153186#comment_235285 sir from your code i can get an cluster head and cluster head member. But i want to get their residual energy also ('energy'(S.E in my code)).For every node i want.(i need both cluster head and cluster member energy).
Mark Neoglobal
2015년 9월 20일
hello. i am using this code and need to display the number of packets received and sent by each cluster head. how is it possible. any help?
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Voronoi Diagram에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)