Plotting users in Matlab

2 visualizaciones (últimos 30 días)
Aftab Ahmed Khan
Aftab Ahmed Khan el 21 de Jul. de 2014
Respondida: Star Strider el 21 de Jul. de 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.

Respuesta aceptada

Star Strider
Star Strider el 21 de Jul. de 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

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by