How can I modify the code to get the sensors with the positions that fulfill the conditions below?
1 次查看(过去 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
采纳的回答
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
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!