How can I modify the code to get the sensors with the positions that fulfill the conditions below?

2 次查看(过去 30 天)
function [Rhoc,Alfac,Rhoc2,Alfac2]= TheRightSensors(W,n,R)
for i=1:n
%R is the Radius of the disk where the sensor nodes are positioned. The center of the disk is P and radius is R.
%Other sensors are put in the disk D(P,2R)
delta=R/6; %delta is a threeshold parameter set to filter out the nodes far away from the critical trajectory
rhoi=randi(W);% rho is the radius of each sensor which is random, and the max limit is W,
%rhoi is suposed to be a vector that contains the values of radius for
%the n sensors
Alfai=randi(2*pi); % Alfa is the angle that defines the position of the sensor and takes
%ranndom values between 0:2*pi for n sensors
if rhoi-R<delta %We are interested for sensors that fulfill this condition
Rhoc=rhoi; %Contains the radiuses of the selected sensors
Alfac=Alfai; %Contains the angles of the selected sensors
if Alfai-Alfac > 2*Theta %After the first selection of the sensors, we select again the sensors
%that fulfill the condition of the angle
Alfac2=Alfac; %Alfac2 is supposed to be a vector that
%saves the angles of the sensors that fulfill the condition
Rhoc2=Rhoc; %Rhoc2 is supposed to be a vector that
%saves the radius of the sensors that fulfill the condition
end
end
%Based on the outputs, we can define the filtered sensors
  3 个评论
Jenny
Jenny 2018-1-14
I understand and I apologise for the confusion. This is the last one. Before I was trying to solve it by taking into consideration only 10 nodes, but it is not a valid solution. The solution should be for n nodes. If someone can help, I would be so thankful.
Jenny
Jenny 2018-1-15
Jan could you please help me to modify the code above to do realize the functions explained in the comments? Thanks.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2018-1-15
You have
rhoi=randi(W);% rho is the radius of each sensor which is random, and the max limit is W, %rhoi is suposed to be a vector that contains the values of radius for %the n sensors
That would be the case for
rhoi=randi(W, 1, n);% rho is the radius of each sensor which is random, and the max limit is W, %rhoi is suposed to be a vector that contains the values of radius for %the n sensors
This assumes that you want discrete positive integer values for the radii.
  15 个评论
Walter Roberson
Walter Roberson 2018-1-17
You are asking me to do all the essential work, but that is not something that interests me.
Generate some random points in cartesian coordinates. Find their centroid and call that P = (Px, Py) . Subtract that centroid from all of the other coordinates to get relative (x,y) coordinates for each. Convert to polar notation. Now sort those according to the angle. Proceed with the filtering.
Jenny
Jenny 2018-1-17
编辑:Jenny 2018-1-17
Ok. But can you help me only with the right code that will apply the condition in the vector, and save the sensors that fulfill the condition in another vector?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Voronoi Diagram 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by