How to count number of devices in a given area ?

조회 수: 3 (최근 30일)
Cladio Andrea
Cladio Andrea 2014년 12월 2일
댓글: Mohammad Abouali 2014년 12월 2일
Hello everyone, i am trying to compare some traffic models fro machine type communication and i have a problem now. I have a given area 1000x1000 and there are some devices randomly placed in this area and lets say i have 2 base station and radius of the coverage area of those base stations. I want to write such a code that let me color the nodes in that coverage area and give me the number of devices inside? Can anyone help about that? Here i have attached the given scenario. Thank you so much in advance.

채택된 답변

Mohammad Abouali
Mohammad Abouali 2014년 12월 2일
If you know the polygon defining the coverage all you need to do is find out if a point falls in that coverage or not.
MATLAB has a built-in function for that called inpolygon().
Check your points against each coverage polygon and then plot them with different colors or count them. but seeing how many true the inpolygon would return.
  댓글 수: 2
Cladio Andrea
Cladio Andrea 2014년 12월 2일
I was exactly looking for that fucntion. Thank you so much Mohammad!!
Mohammad Abouali
Mohammad Abouali 2014년 12월 2일
You are welcome

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Guillaume
Guillaume 2014년 12월 2일
Isn't it as simple as calculating the distance from the device to the base station and comparing that to the radius?
devices = randi([0 999], 100, 2); %100 random devices, col1=x, col2 = y
basestation = [999 0];
radius = 600;
distsquared = sum(bsxfun(@minus, devices, basestation).^2, 2)
inrange = distsquared <= radius.^2;
  댓글 수: 2
Cladio Andrea
Cladio Andrea 2014년 12월 2일
Thank you Gulillaume , i will just change the devices line i guess in that case, becasuse i already have the code to locate nodes randomly in a given area , thank you again!
Mohammad Abouali
Mohammad Abouali 2014년 12월 2일
Cladio, if your coverage area is circular, then Guillaume approach is going to be much faster than using inpolygon. That function is good if you have non-circular coverage.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by