I placed 50 random node in the area of 180*40.
Now how to give number to that random node from 1-50 and also how to calculate the coordinates of each random node.

4 Kommentare

TADA
TADA am 8 Dez. 2018
You Can Use randperm To Generate A Vector Of 1-50 ordered Randomly.
As For Coordinates, If I Get You Right, It Depends On How The Area Is Divided.
Sushree Patra
Sushree Patra am 8 Dez. 2018
Thank you for the solution
i am plotting like this
x = 301* rand(50,1);
y= 160*rand(50,1);
plot(x,y, 'b*');
it randomly placed 50 blue star on the area of 301*160
my object is to numbering all the blue star from 1-50
Jan
Jan am 9 Dez. 2018
I do not understand the question. What does "give number" mean? If you have placed the "nodes" (what ever this means) already, you do have the corrdinates. So what do you want to calculate?
Sushree Patra
Sushree Patra am 9 Dez. 2018
Thank you sir jan for the response.
well, actually the thing is in a plot I placed 50 points randomly. Now i have to provide 1-50 number each random point.
Problem is - In a area or 301*160 I placed 13 points according to thr coordinates and 50 random points randomly now i have to number each point to find out wich points are closer to selected coordinates point.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Image Analyst
Image Analyst am 9 Dez. 2018

1 Stimme

Since each point is a random number, there is no need to shuffle/randomize their indexes in the x and y array afterwards. If you think there is for some reason, then tell us the reason why x and y will need to be randomly shuffled with randperm:
x = x(randperm(length(x)));
y = y(randperm(length(y)));
It's not clear why you need to do this.

7 Kommentare

Sushree Patra
Sushree Patra am 9 Dez. 2018
Thank you sir for your response.
Well, I will describe the whole thing what is my objective.
step 1: I have to take a area of 301*160 which is approximately a human body then I placed 13 nodes which are predefined and having fixed position. Then I have to place 50 relay node called as relay node in the area of 301*160. and one sink/ output node in the fixed coordinate.
step2: I have to calculate the distance from each 13 node to 50 randomly placed node, each 50 node to that sink node and each 13 node to sink node. So here i have to calculate all distance.
step3 : If the distance of that 13 node to output/sink node is more than 30cm then i have to choose nearest relay node among the 50 node.
Step4: I have to calculate transmission energy which have fixed formula of each 13 node which transmitting data to that output node.
step5: if the 13 node have greater distance of 30c then i have to calculate the energy consumption of that choosen node of 50 random node which have also fixed formula.(Receiving energy which received data from one of the 13 node + transmission energy of that choosen relay node)
To "now i have to number each point to find out wich points are closer to selected coordinates point" then use sqrt() and masking
% Get distance of every point to (xSelected, ySelected)
distances = sqrt((x - xSelected) .^ 2 + (y - ySelected).^2)
% Find distances less than 0.35 or whatever:
logicalIndexes = distances < 0.35;
% Extract any and all points with x and y within that distance:
xNearby = x(logicalIndexes);
yNearby = y(logicalIndexes);
% To find only the one single closest:
[minDistance, indexOfClosest] = min(distances)
xClosest = x(indexOfClosest)
yClosest = y(indexOfClosest)
Sushree Patra
Sushree Patra am 9 Dez. 2018
Thank you very much Sir.
I got which node is with in the range. Now for excluding that node i have to find out nearest relay node which is in between that node to sink node
so for that what i have to do
Sushree Patra
Sushree Patra am 9 Dez. 2018
clc;
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 25;
figure;
imshow('pc3.png');
%legend('Relay', 'Sink', 'Sensor');
x1 = [105,107,58,58,75,146,118,18,48,55,108,80,80];
y1 = [190,280,190,280,145,153,103,153,103,65,65,50,10];
hold on
A=100;
B=140;
plot(A,B, 'mo-', 'MarkerSize', 10,'LineWidth', 2);
hold on
%Make 75 points in set #2
Xmin = 30;
Xmax = 130;
x2 = Xmin+rand(1,50)*(Xmax-Xmin);
Ymin = 20;
Ymax= 260;
y2 = Ymin+rand(1,50)*(Ymax-Ymin);
%numPoints2 = 50;
%x2 = 167*rand(50, 1);
%y2 = 302*rand(50, 1);
for i = 1:50
text(x2(i),y2(i),num2str(i));
end
for i = 1:13
text(x1(i),y1(i),num2str(i));
end
% Plot set 1 in red
plot(x1, y1, 'r.', 'MarkerSize', 13);
% Plot set 2 in blue
hold on;
plot(x2, y2, 'b*', 'MarkerSize', 5);
grid on;
for i=1:13
for j=1:50
% Find distances between every point in set 1 to every point in set #2.
distances(i,j) = pdist2([x1(i),y1(i)], [x2(j), y2(j)], 'euclidean');
end
minDistance(i) = min(distances(i,:));
end
% Find min distance
disp (distances);
dist1 = sqrt((x2-A).^2+(y2-B).^2)
%disp (dist1);
dist2 =sqrt((x1-A).^2+(y1-B).^2)
logicalindexes = dist2 < 30.00000;
x1Nearby = x1(logicalindexes)
y1Nearby = y1(logicalindexes)
%if (dist2>30)
disp (minDistance);
pc3.png
Sushree Patra
Sushree Patra am 9 Dez. 2018
The node whic are note in the range (30cm) then that node send data to the nearest relay node and then relay node transmitting that received data to the sink node
So for that what i have to do?
Image Analyst
Image Analyst am 9 Dez. 2018
I don't know what relay nodes and sink nodes are. Sorry, but I don't have time to delve into your project and co-develop it with you. I hope by seeing how I computed distances, and found nearby ones and the closest ones, you can adapt it as needed. It really shouldn't be that hard. Good luck.
Sushree Patra
Sushree Patra am 9 Dez. 2018
Thank you for your Solutions and response. I ll try by my self.
relay node: which helps to forword the data.
sink node: one output device.
Thank you

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by