Plotting users in Matlab

2 visualizzazioni (ultimi 30 giorni)
Aftab Ahmed Khan
Aftab Ahmed Khan il 21 Lug 2014
Risposto: Star Strider il 21 Lug 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.

Risposta accettata

Star Strider
Star Strider il 21 Lug 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

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by