Plotting users in Matlab

2 views (last 30 days)
Aftab Ahmed Khan
Aftab Ahmed Khan on 21 Jul 2014
Answered: Star Strider on 21 Jul 2014
Hi everyone, I have coded the following figure, in which the users are randomly distributed between the four blocks. I want the users to be only on the street, not inside the building block. Any help will be really appreciated. Thank you guys.

Accepted Answer

Star Strider
Star Strider on 21 Jul 2014
Use the inpolygon function:
Compare the two plots:
Users = 2*rand(20,2);
Bldg = [0.5 0.5; 0.5 1.5; 1.5 1.5; 1.5 0.5; 0.5 0.5];
figure(1)
plot(Bldg(:,1), Bldg(:,2))
hold on
scatter(Users(:,1), Users(:,2), 'xb')
hold off
axis([0 2 0 2])
axis equal square
Street = inpolygon(Users(:,1), Users(:,2), Bldg(:,1), Bldg(:,2));
figure(2)
plot(Bldg(:,1), Bldg(:,2))
hold on
scatter(Users(Street==0,1), Users(Street==0,2), 'xb')
hold off
axis([0 2 0 2])
axis equal square

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!