How can I modify the code to get the sensors with the positions that fulfill the conditions below?
1 view (last 30 days)
Show older comments
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
Accepted Answer
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
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.
More Answers (0)
See Also
Categories
Find more on Logical 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!