How to find the nearest neighbors points in this case ?

just see this image 1 in this they where creating wsn(wireless sensor network). This i have done in matlab you can see my coding also i attached below.
Image-1
Image-2
in this image they are finding nearest sensor node gateway's, so now i want to find the sensor node nearest sensor node gateway's please help me..

4 件のコメント

Image Analyst
Image Analyst 2014 年 12 月 6 日
編集済み: Image Analyst 2014 年 12 月 6 日
Why is the g5 gateway green instead of blue?
And do you have to start with an image instead of a list?
And I don't exactly understand the grammar of "find the sensor node nearest sensor node gateway's". What is an example input, and the expected output for that input? How many nodes are you putting in? Or are you just inputting an image and need to derive the list from the image?
Matlab111
Matlab111 2014 年 12 月 7 日
sir,
1. g5 is also gateway by mistake it's in blue.
2. sir, just run my code that i have given below after executing that code you will get figure in that 'X' is denoted as gateway node and 'o' this denoted as normal sensor node's. By using this diagram you can get that table.
3. " And I don't exactly understand the grammar of "find the sensor node nearest sensor node gateway's". " actually i need to find the nearest sensor nodes of the gateway, you can look at that table(IMAGE-2) in that s1 is an sensor node and nearest to that sensor node's gateway node's i want to find that is {g3,g1,g2}.
4. 'What is an example input, and the expected output for that input? ' for input you can see my code, and output should be like a IMAGE-2.
5. ' How many nodes are you putting in? ' no.of node's is 100.
6.' are you just inputting an image and need to derive the list from the image? '- no sir,
Image Analyst
Image Analyst 2014 年 12 月 7 日
I just blindly ran the code and it made this:
It doesn't look anything like your gateway and sensor node image with the blue and green spots above. Can you explain this plot? It's not explained in the code - the comments are very very minimal. And I don't see any image, just a plot or scatterplot.
Matlab111
Matlab111 2014 年 12 月 7 日
sir, in this figure 'X' is denoted as gateway node and 'o' this denoted as normal sensor node's.

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

 採用された回答

Image Analyst
Image Analyst 2014 年 12 月 7 日

1 投票

So you don't have to start with an image. You have a list of (x,y) coordinates for gateways and sensors. So why can't you just run through the list with a for loop calculating the distance of each gateway to all the sensors, and select sensors that are closer than some specified distance? Just use the Pythagorean theorem and a double for loop. Draw lines to "close" pairs. Seems pretty easy.

6 件のコメント

Matlab111
Matlab111 2014 年 12 月 7 日
sir, actually i don't no how to do that exactly.
Image Analyst
Image Analyst 2014 年 12 月 7 日
編集済み: Image Analyst 2014 年 12 月 7 日
OK, I did it for you. Look in the attached m-file which creates this image. It draws lines from each gateway to any sensor that is within a distance of 10 to it. If this answers the question, can you go ahead and mark the Answer as "Accepted"?
Matlab111
Matlab111 2014 年 12 月 7 日
yes sir thanks a lot, now i'm getting but i want to display the values also like this
X(coordinates) Y(coordinates)
Sensor node: 30.6946 42.2466
Gateway : X(coordinates) Y(coordinates)
41.2224 145.9893
44.6558 50.4247
74.9058 90.0280
like this i want't to display (like want to display what are all the sensor nodes connected to the gateway node's) for reference see the image-2 in above my question.
Image Analyst
Image Analyst 2014 年 12 月 7 日
You're welcome. Can you mark it as Accepted then?
For the printing, you can just use fprintf(). I'm sure you can figure it out - it's not hard at all. You can get it to print out whatever you want. For example
fprintf(' X(coordinates) Y(coordinates)\n');
fprintf(' Sensor node: %15f %15f', x, y);
fprintf(' Gateway : X(coordinates) Y(coordinates)\n');
and so on.
Matlab111
Matlab111 2014 年 12 月 7 日
sir what that "%15f %15f" indicates in "fprintf(' Sensor node: %15f %15f', x, y);"
Matlab111
Matlab111 2014 年 12 月 7 日
ya sir i got it. Thank's a lot....

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

その他の回答 (1 件)

Rohini Sharma
Rohini Sharma 2015 年 4 月 30 日

0 投票

Hello Arul and Image Analyst
How to modify the code in order to connect gateway node with only one sensor node? Here gateway node is connection to all sensor node with in its range=10.
Please reply Thanks

カテゴリ

ヘルプ センター および File ExchangeWSNs についてさらに検索

質問済み:

2014 年 12 月 6 日

回答済み:

2015 年 4 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by