Clear Filters
Clear Filters

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

2 views (last 30 days)
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 Comments
Jenny
Jenny on 14 Jan 2018
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 on 15 Jan 2018
Jan could you please help me to modify the code above to do realize the functions explained in the comments? Thanks.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 15 Jan 2018
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 Comments
Walter Roberson
Walter Roberson on 17 Jan 2018
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 on 17 Jan 2018
Edited: Jenny on 17 Jan 2018
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?

Sign in to comment.

More Answers (0)

Categories

Find more on Voronoi Diagram in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!