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

1 visualización (últimos 30 días)
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 comentarios
Jenny
Jenny el 14 de En. de 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 el 15 de En. de 2018
Jan could you please help me to modify the code above to do realize the functions explained in the comments? Thanks.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 15 de En. de 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 comentarios
Walter Roberson
Walter Roberson el 17 de En. de 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 el 17 de En. de 2018
Editada: Jenny el 17 de En. de 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?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by