Comparing vector elements by percentage

Angle=[5 10 20 60 180 190 195 300 310], these angles determine the possible directions of robots. If there are 2 robots starting with the same angle or plus minus 5%(5 degrees) they will make collision. I'd like to have the result in on vector such that:[2 2 1 1 1 2 2 1 1]. Any help?

5 comentarios

Geoff Hayes
Geoff Hayes el 1 de Nov. de 2015
yousef - why will two robots collide if they have similar directions? Won't their starting position and speeds also impact whether they collide or not?
yousef Yousef
yousef Yousef el 1 de Nov. de 2015
All robots start at the same time with the same speed.Thanks
Is there any mistake here?
Angle=[5 10 20 60 180 190 200 300 310];
collision=[];
for i=1:9
targetValue = Angle(i);
tolerance = 0.05 * targetValue;
differences = abs(Angle-targetValue) ;
inToleranceIndexes = differences < tolerance;
withinTolerance = Angle(inToleranceIndexes)
collision(i)= Angle(inToleranceIndexes)
end
end
Stefan Raab
Stefan Raab el 2 de Nov. de 2015
Editada: Stefan Raab el 2 de Nov. de 2015
Hello,
the codeline
collision(i)= Angle(inToleranceIndexes)
won't work, if inToleranceIndexes has more than one value==1. Then Angle(inToleranceIndexes) i.e. is [300 310] and you can't assign a vector to a single element as you do with collision(i).
But a question in general: You say tolerance is 0.05*targetValue, that means your tolerance increases with increasing start-angle. Is this really how it is supposed to be?
Best regards, Stefan
yousef Yousef
yousef Yousef el 2 de Nov. de 2015
Hi,the tolerance is plus minus 5 degrees.The tolerance is fixed and can not be changed.I have another try,please check it.
  • Angle=[5 10 20 60 180 190 200 300 310];
  • collision=[];
  • for i=1:9
  • c=[];
  • targetValue = Angle(i);
  • tolerance = 0.5 * targetValue;
  • differences = abs(Angle-targetValue) ;
  • inToleranceIndexes = differences < tolerance;
  • withinTolerance = Angle(inToleranceIndexes);
  • c=[c;inToleranceIndexes];
  • end
  • collision=[collision;c];

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 2 de Nov. de 2015

0 votos

As mentioned in your duplicate question there will be no collision unless you have different starting points. And all your code does is tell you that each angle interferes/collides with no other angle except itself, which is pretty useless.

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 1 de Nov. de 2015

Respondida:

el 2 de Nov. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by