フィルターのクリア

Please help me there is something wrong in this dvhop code

2 ビュー (過去 30 日間)
zeyneb khalili
zeyneb khalili 2017 年 4 月 26 日
編集済み: zeyneb khalili 2017 年 4 月 28 日
if true
% BorderLength-----
% NodeAmount-------
% BeaconAmount-----
% Sxy--------------
% Beacon-----------
% UN---------------
% Distance----
% h---------------
% X---------------
% R------------
clear,close all;
BorderLength=100;
NodeAmount=100;
R=20;
C=BorderLength.*rand(2,NodeAmount);
Sxy=[[1:NodeAmount];C];
for Z=1:10;
%Z=5;
Rate(Z)=(5*Z)/100;
BeaconAmount=NodeAmount*Rate(Z);
UNAmount=NodeAmount-BeaconAmount;
h=zeros(NodeAmount,NodeAmount);
X=zeros(2,UNAmount);
Beacon=[Sxy(2,1:BeaconAmount);Sxy(3,1:BeaconAmount)];
UN=[Sxy(2,(BeaconAmount+1):NodeAmount);Sxy(3,(BeaconAmount+1):NodeAmount)];
figure;
plot(Sxy(2,1:BeaconAmount),Sxy(3,1:BeaconAmount),'r*',Sxy(2,(BeaconAmount+1):NodeAmount),Sxy(3,(BeaconAmount+1):NodeAmount),'k.')
xlim([0,BorderLength]);
ylim([0,BorderLength]);
title('* Red beacon nodes . Black unknown node')
for i=1:NodeAmount
for j=1:NodeAmount
Dall(i,j)=((Sxy(2,i)-Sxy(2,j))^2+(Sxy(3,i)-Sxy(3,j))^2)^0.5;
if (Dall(i,j)<=R)&(Dall(i,j)>0)
h(i,j)=1;
elseif i==j
h(i,j)=0;
else h(i,j)=inf;
end
end
end
for k=1:NodeAmount
for i=1:NodeAmount
for j=1:NodeAmount
if h(i,k)+h(k,j)<h(i,j)%min(h(i,j),h(i,k)+h(k,j))
h(i,j)=h(i,k)+h(k,j);
end
end
end
end
%h
%Dhop=zeros(1,UNAmount);
h1=h(1:BeaconAmount,1:BeaconAmount);
D1=Dall(1:BeaconAmount,1:BeaconAmount);
for i=1:BeaconAmount
dhop(i,1)=sum(D1(i,:))/sum(h1(i,:));
end
D2=Dall(1:BeaconAmount,(BeaconAmount+1):NodeAmount);
for i=1:BeaconAmount
for j=1:UNAmount
if min(D2(:,j))==D2(i,j)
Dhop(1,j)=D2(i,j);
end
end
end
%Dhop
Distance=zeros(BeaconAmount,UNAmount);
hop1=h(1:BeaconAmount,(BeaconAmount+1):NodeAmount);%
for i=1:UNAmount
hop=Dhop(1,i);
Distance(:,i)=hop*hop1(:,i);
end
d=Distance;
for i=1:2
for j=1:(BeaconAmount-1)
a(i,j)=Beacon(i,j)-Beacon(i,BeaconAmount);
end
end
A=-2*(a');
% d=d1';
for m=1:UNAmount
for i=1:(BeaconAmount-1)
B(i,1)=d(i,m)^2-d(BeaconAmount,m)^2-Beacon(1,i)^2+Beacon(1,BeaconAmount)^2-Beacon(2,i)^2+Beacon(2,BeaconAmount)^2;
end
X1=inv(A'*A)*A'*B;
X(1,m)=X1(1,1);
X(2,m)=X1(2,1);
end
%UN
%X
for i=1:UNAmount
error(1,i)=(((X(1,i)-UN(1,i))^2+(X(2,i)-UN(2,i))^2)^0.5);
end
avgerror(Z)=sum(error)/UNAmount
Accuracy(Z)=avgerror(Z)*100/R;
end
figure;
plot(Rate, Accuracy,'-or')
xlabel('proportion of bacon Rate');
ylabel('position Accuracy/%');
title('the average location of each node')
end
// I replaced this section:
if true
D2=Dall(1:BeaconAmount,(BeaconAmount+1):NodeAmount);
for i=1:BeaconAmount
for j=1:UNAmount
if min(D2(:,j))==D2(i,j)
Dhop(1,j)=D2(i,j);
end
end
end
%Dhop
Distance=zeros(BeaconAmount,UNAmount);
hop1=h(1:BeaconAmount,(BeaconAmount+1):NodeAmount);%
for i=1:UNAmount
hop=Dhop(1,i);
Distance(:,i)=hop*hop1(:,i);
end
end
//with this one:
if true
Distance=zeros(BeaconAmount,UNAmount);
hop1=h(1:BeaconAmount,(BeaconAmount+1):NodeAmount);
for i=1:BeaconAmount
for j=1:UNAmount
if min(hop1(:,j))==hop1(i,j)
Dhop(j,1)=dhop(i,1);
end
end
end
for i=1:UNAmount
hop=Dhop(i,1);
Distance(:,i)=hop*hop1(:,i);
end
end
Cause in dvhop algorithm we need least hop count to calculate distance between unknown node and each beacon. We impose in first that we don't know coordinates of unknown nodes. Am I right?
  1 件のコメント
Jan
Jan 2017 年 4 月 26 日
Do you see that it is impossible to read your code? Please use the "{} code" button to give us a chance to see, what you are asking for.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by