MATLAB: Plotting users in Matlab

plotting

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.

Best Answer

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